forked from tedkulp/silk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.silk_bootstrap.php
109 lines (93 loc) · 2.97 KB
/
class.silk_bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
// The MIT License
//
// Copyright (c) 2008 Ted Kulp
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/**
* Methods for starting up a web application.
*
* @since 1.0
* @author Ted Kulp
**/
class SilkBootstrap extends SilkObject
{
static private $instance = NULL;
function __construct()
{
parent::__construct();
}
/**
* Returns an instnace of the SilkBookstrap singleton.
*
* @return SilkBookstrap The singleton SilkBookstrap instance
* @author Ted Kulp
**/
static public function get_instance()
{
if (self::$instance == NULL)
{
self::$instance = new SilkBootstrap();
}
return self::$instance;
}
public function setup()
{
//Load up the configuration file
if (is_file(join_path(ROOT_DIR, 'config', 'setup.yml')))
$config = SilkYaml::load(join_path(ROOT_DIR, 'config', 'setup.yml'));
else
die("Config file not found!");
//Add class path entries
if (isset($config['class_autoload']))
{
foreach ($config['class_autoload'] as $dir)
{
add_class_directory(join_path(ROOT_DIR, $dir));
}
}
//Setup session stuff
SilkSession::setup();
//Setup the database connection
if (!isset($config['database']['dsn']))
die("No database information found in the configuration file");
if (null == SilkDatabase::connect($config['database']['dsn'], $config['debug'], true, $config['database']['prefix']))
die("Could not connect to the database");
silk()->set('config', $config);
//Load components
SilkComponentManager::load();
}
public function run()
{
//Kick the profiler so we get a fairly accurate run time
//Though, this doesn't include the classdir scanning, but
//it's still pretty close
SilkProfiler::get_instance();
self::setup();
//Process route
SilkRequest::handle_request();
$config = silk()->get('config');
if ($config['debug'])
{
echo SilkProfiler::get_instance()->report();
}
}
}
# vim:ts=4 sw=4 noet
?>