1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\DI; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Anax base class implementing Dependency Injection / Service Locator |
7
|
|
|
* of the services used by the framework, using lazy loading. |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
class CDIFactoryDefault extends CDI |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Construct. |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
1 |
|
public function __construct() |
17
|
|
|
{ |
18
|
1 |
|
parent::__construct(); |
19
|
|
|
|
20
|
1 |
|
require ANAX_APP_PATH . 'config/error_reporting.php'; |
21
|
|
|
|
22
|
|
|
$this->setShared('response', function () { |
23
|
|
|
$response = new \Anax\Response\CResponseBasic(); |
24
|
|
|
$response->setDI($this); |
25
|
|
|
return $response; |
26
|
1 |
|
}); |
27
|
|
|
|
28
|
1 |
|
$this->setShared('validate', '\Anax\Validate\CValidate'); |
29
|
1 |
|
$this->setShared('flash', '\Anax\Flash\CFlashBasic'); |
30
|
|
|
|
31
|
1 |
|
$this->set('route', '\Anax\Route\CRouteBasic'); |
32
|
1 |
|
$this->set('view', '\Anax\View\CViewBasic'); |
33
|
|
|
|
34
|
|
|
$this->set('ErrorController', function () { |
35
|
|
|
$controller = new \Anax\MVC\ErrorController(); |
36
|
|
|
$controller->setDI($this); |
37
|
|
|
return $controller; |
38
|
1 |
|
}); |
39
|
|
|
|
40
|
|
|
$this->setShared('log', function () { |
41
|
|
|
$log = new \Anax\Log\CLogger(); |
42
|
|
|
$log->setContext('development'); |
43
|
|
|
return $log; |
44
|
1 |
|
}); |
45
|
|
|
|
46
|
|
|
$this->setShared('request', function () { |
47
|
|
|
$request = new \Anax\Request\CRequestBasic(); |
48
|
|
|
$request->init(); |
49
|
|
|
return $request; |
50
|
1 |
|
}); |
51
|
|
|
|
52
|
|
|
$this->setShared('url', function () { |
53
|
|
|
$url = new \Anax\Url\CUrl(); |
54
|
|
|
$url->setSiteUrl($this->request->getSiteUrl()); |
|
|
|
|
55
|
|
|
$url->setBaseUrl($this->request->getBaseUrl()); |
|
|
|
|
56
|
|
|
$url->setStaticSiteUrl($this->request->getSiteUrl()); |
|
|
|
|
57
|
|
|
$url->setStaticBaseUrl($this->request->getBaseUrl()); |
|
|
|
|
58
|
|
|
$url->setScriptName($this->request->getScriptName()); |
|
|
|
|
59
|
|
|
$url->setUrlType($url::URL_APPEND); |
60
|
|
|
return $url; |
61
|
1 |
|
}); |
62
|
|
|
|
63
|
|
|
$this->setShared('views', function () { |
64
|
|
|
$views = new \Anax\View\CViewContainerBasic(); |
65
|
|
|
$views->setBasePath(ANAX_APP_PATH . 'view'); |
66
|
|
|
$views->setFileSuffix('.tpl.php'); |
67
|
|
|
$views->setDI($this); |
68
|
|
|
return $views; |
69
|
1 |
|
}); |
70
|
|
|
|
71
|
|
|
$this->setShared('router', function () { |
72
|
|
|
|
73
|
|
|
$router = new \Anax\Route\CRouterBasic(); |
74
|
|
|
$router->setDI($this); |
75
|
|
|
|
76
|
|
View Code Duplication |
$router->addInternal('403', function () { |
|
|
|
|
77
|
|
|
$this->dispatcher->forward([ |
|
|
|
|
78
|
|
|
'controller' => 'error', |
79
|
|
|
'action' => 'statusCode', |
80
|
|
|
'params' => [ |
81
|
|
|
'code' => 403, |
82
|
|
|
'message' => "HTTP Status Code 403: This is a forbidden route.", |
83
|
|
|
], |
84
|
|
|
]); |
85
|
|
|
})->setName('403'); |
86
|
|
|
|
87
|
|
|
$router->addInternal('404', function () { |
88
|
|
|
$this->dispatcher->forward([ |
|
|
|
|
89
|
|
|
'controller' => 'error', |
90
|
|
|
'action' => 'statusCode', |
91
|
|
|
'params' => [ |
92
|
|
|
'code' => 404, |
93
|
|
|
'message' => "HTTP Status Code 404: This route is not found.", |
94
|
|
|
], |
95
|
|
|
]); |
96
|
|
|
$this->dispatcher->forward([ |
|
|
|
|
97
|
|
|
'controller' => 'error', |
98
|
|
|
'action' => 'displayValidRoutes', |
99
|
|
|
]); |
100
|
|
|
})->setName('404'); |
101
|
|
|
|
102
|
|
View Code Duplication |
$router->addInternal('500', function () { |
|
|
|
|
103
|
|
|
$this->dispatcher->forward([ |
|
|
|
|
104
|
|
|
'controller' => 'error', |
105
|
|
|
'action' => 'statusCode', |
106
|
|
|
'params' => [ |
107
|
|
|
'code' => 500, |
108
|
|
|
'message' => "HTTP Status Code 500: There was an internal server or processing error.", |
109
|
|
|
], |
110
|
|
|
]); |
111
|
|
|
})->setName('500'); |
112
|
|
|
|
113
|
|
|
return $router; |
114
|
1 |
|
}); |
115
|
|
|
|
116
|
|
|
$this->setShared('dispatcher', function () { |
117
|
|
|
$dispatcher = new \Anax\MVC\CDispatcherBasic(); |
118
|
|
|
$dispatcher->setDI($this); |
119
|
|
|
return $dispatcher; |
120
|
1 |
|
}); |
121
|
|
|
|
122
|
|
|
$this->setShared('session', function () { |
123
|
|
|
$session = new \Anax\Session\CSession(); |
124
|
|
|
$session->configure(ANAX_APP_PATH . 'config/session.php'); |
125
|
|
|
$session->name(); |
126
|
|
|
$session->start(); |
127
|
|
|
return $session; |
128
|
1 |
|
}); |
129
|
|
|
|
130
|
|
|
$this->setShared('theme', function () { |
131
|
|
|
$themeEngine = new \Anax\ThemeEngine\CThemeBasic(); |
132
|
|
|
$themeEngine->setDI($this); |
133
|
|
|
$themeEngine->configure(ANAX_APP_PATH . 'config/theme.php'); |
134
|
|
|
return $themeEngine; |
135
|
1 |
|
}); |
136
|
|
|
|
137
|
|
|
$this->setShared('navbar', function () { |
138
|
|
|
$navbar = new \Anax\Navigation\CNavbar(); |
139
|
|
|
$navbar->setDI($this); |
140
|
|
|
$navbar->configure(ANAX_APP_PATH . 'config/navbar.php'); |
141
|
|
|
return $navbar; |
142
|
1 |
|
}); |
143
|
|
|
|
144
|
|
|
$this->set('fileContent', function () { |
145
|
|
|
$fc = new \Anax\Content\CFileContent(); |
146
|
|
|
$fc->setBasePath(ANAX_APP_PATH . 'content/'); |
147
|
|
|
return $fc; |
148
|
1 |
|
}); |
149
|
|
|
|
150
|
1 |
|
$this->setShared('textFilter', function () { |
151
|
|
|
$filter = new \Anax\Content\CTextFilter(); |
152
|
|
|
$filter->setDI($this); |
153
|
|
|
$filter->configure(ANAX_APP_PATH . 'config/text_filter.php'); |
154
|
|
|
return $filter; |
155
|
1 |
|
}); |
156
|
1 |
|
} |
157
|
|
|
} |
158
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.