1 <?php
2
3 use Docolight\Support\Facade;
4 use Docolight\Container\Container;
5 use Docolight\Support\ClassLoader;
6
7 8 9 10 11
12 class Docolight extends CApplicationComponent
13 {
14 15 16
17 const PHP_MINIMUM_VERSION = 50400;
18
19 20 21 22 23
24 protected $libraries = array();
25
26 27 28 29 30
31 protected $rootPath = 'libs';
32
33 34 35
36 public function init()
37 {
38
39
40 $this->registerAutoload();
41
42 $this->loadHelpers();
43
44 $this->registerApplicationComponents();
45
46 Facade::set(container());
47 }
48
49 50 51 52 53 54 55
56 protected function checkEnvironment()
57 {
58 if (!(PHP_VERSION_ID > static::PHP_MINIMUM_VERSION)) {
59 throw new RuntimeException('Your PHP Version must be at least 5.4 to use this library!');
60 }
61 }
62
63 64 65
66 protected function loadHelpers()
67 {
68 require_once Yii::getPathOfAlias('application.libs.docolight.Docolight.Support.helpers').'.php';
69 }
70
71 72 73
74 protected function registerApplicationComponents()
75 {
76 Yii::app()->setComponent('container', new Container());
77
78 container()->bind('app', function () {
79 return Yii::app();
80 });
81
82 container()->bindIf('Docolight\Http\ResponseFactory', 'Docolight\Http\ResponseFactory', true);
83
84 Yii::app()->setComponent('response', container('Docolight\Http\ResponseFactory'));
85
86 container()->alias('Docolight\Http\ResponseFactory', 'response');
87 }
88
89 90 91
92 protected function registerAutoload()
93 {
94 require_once Yii::getPathOfAlias("application.{$this->rootPath}.docolight.Docolight.Support.ClassLoader").'.php';
95
96 if ($librariesPath = realpath(Yii::getPathOfAlias("application.{$this->rootPath}"))) {
97 foreach (array_merge($this->getDefaultLibraries(), $this->libraries) as $library) {
98 ClassLoader::addDirectories($librariesPath.DIRECTORY_SEPARATOR.$library);
99 }
100
101 ClassLoader::register();
102 }
103 }
104
105 106 107 108 109
110 final private function getDefaultLibraries()
111 {
112 return array(
113 'symfony',
114 'carbon',
115 'docolight',
116 'docoflow',
117 'docotory',
118 );
119 }
120 }
121