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
|
|
|
class CDIFactoryDefault extends CDI |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Load config file from ANAX_APP_PATH or ANAX_INSTALL_PATH. |
13
|
|
|
* |
14
|
|
|
* @param string $filename to load. |
15
|
|
|
* |
16
|
|
|
* @throws Exception when $filenam is not found. |
17
|
|
|
* |
18
|
|
|
* @return void |
19
|
|
|
*/ |
20
|
1 |
|
public function loadFile($filename) |
21
|
|
|
{ |
22
|
1 |
|
$pathInstall = ANAX_INSTALL_PATH . "/config/$filename"; |
23
|
1 |
|
$pathApp = ANAX_APP_PATH . "/config/$filename"; |
24
|
|
|
|
25
|
1 |
|
if (is_readable($pathApp)) { |
26
|
|
|
require $pathApp; |
27
|
|
|
return; |
28
|
1 |
|
} elseif (is_readable($pathInstall)) { |
29
|
1 |
|
require $pathInstall; |
30
|
1 |
|
return; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
throw new Exception("Configure item '$filename' is not a readable file."); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Construct. |
40
|
|
|
* |
41
|
|
|
*/ |
42
|
1 |
|
public function __construct() |
43
|
|
|
{ |
44
|
1 |
|
parent::__construct(); |
45
|
|
|
|
46
|
1 |
|
$this->loadFile("error_reporting.php"); |
47
|
|
|
|
48
|
1 |
|
$this->setShared("response", "\Anax\Response\CResponseBasic"); |
49
|
1 |
|
$this->setShared("validate", "\Anax\Validate\CValidate"); |
50
|
1 |
|
$this->setShared("flash", "\Anax\Flash\CFlashBasic"); |
51
|
|
|
|
52
|
1 |
|
$this->set("route", "\Anax\Route\CRouteBasic"); |
53
|
1 |
|
$this->set("view", "\Anax\View\CView"); |
54
|
|
|
|
55
|
|
|
$this->set("ErrorController", function () { |
56
|
|
|
$controller = new \Anax\MVC\ErrorController(); |
57
|
|
|
$controller->setDI($this); |
|
|
|
|
58
|
|
|
return $controller; |
59
|
1 |
|
}); |
60
|
|
|
|
61
|
|
|
$this->setShared("log", function () { |
62
|
|
|
$log = new \Anax\Log\CLogger(); |
63
|
|
|
$log->setContext("development"); |
64
|
|
|
return $log; |
65
|
1 |
|
}); |
66
|
|
|
|
67
|
|
|
$this->setShared("cache", function () { |
68
|
|
|
$cache = new \Anax\Cache\CFileCache(); |
69
|
|
|
$cache->configure("cache.php"); |
70
|
|
|
return $cache; |
71
|
1 |
|
}); |
72
|
|
|
|
73
|
|
|
$this->setShared("request", function () { |
74
|
|
|
$request = new \Anax\Request\CRequestBasic(); |
75
|
|
|
$request->init(); |
76
|
|
|
return $request; |
77
|
1 |
|
}); |
78
|
|
|
|
79
|
|
|
$this->setShared("url", function () { |
80
|
|
|
$url = new \Anax\Url\CUrl(); |
81
|
|
|
$url->setSiteUrl($this->request->getSiteUrl()); |
|
|
|
|
82
|
|
|
$url->setBaseUrl($this->request->getBaseUrl()); |
|
|
|
|
83
|
|
|
$url->setStaticSiteUrl($this->request->getSiteUrl()); |
|
|
|
|
84
|
|
|
$url->setStaticBaseUrl($this->request->getBaseUrl()); |
|
|
|
|
85
|
|
|
$url->setScriptName($this->request->getScriptName()); |
|
|
|
|
86
|
|
|
$url->setUrlType($url::URL_APPEND); |
87
|
|
|
return $url; |
88
|
1 |
|
}); |
89
|
|
|
|
90
|
|
|
$this->setShared("views", function () { |
91
|
|
|
$views = new \Anax\View\CViewContainer(); |
92
|
|
|
$views->configure("views.php"); |
93
|
|
|
$views->setDI($this); |
|
|
|
|
94
|
|
|
return $views; |
95
|
1 |
|
}); |
96
|
|
|
|
97
|
|
|
$this->setShared("router", function () { |
98
|
|
|
|
99
|
|
|
$router = new \Anax\Route\CRouterBasic(); |
100
|
|
|
$router->setDI($this); |
|
|
|
|
101
|
|
|
|
102
|
|
View Code Duplication |
$router->addInternal("403", function () { |
|
|
|
|
103
|
|
|
$this->dispatcher->forward([ |
|
|
|
|
104
|
|
|
"controller" => "error", |
105
|
|
|
"action" => "statusCode", |
106
|
|
|
"params" => [ |
107
|
|
|
"code" => 403, |
108
|
|
|
"message" => "HTTP Status Code 403: This is a forbidden route.", |
109
|
|
|
], |
110
|
|
|
]); |
111
|
|
|
})->setName("403"); |
112
|
|
|
|
113
|
|
|
$router->addInternal("404", function () { |
114
|
|
|
$this->dispatcher->forward([ |
|
|
|
|
115
|
|
|
"controller" => "error", |
116
|
|
|
"action" => "statusCode", |
117
|
|
|
"params" => [ |
118
|
|
|
"code" => 404, |
119
|
|
|
"message" => "HTTP Status Code 404: This route is not found.", |
120
|
|
|
], |
121
|
|
|
]); |
122
|
|
|
$this->dispatcher->forward([ |
|
|
|
|
123
|
|
|
"controller" => "error", |
124
|
|
|
"action" => "displayValidRoutes", |
125
|
|
|
]); |
126
|
|
|
})->setName("404"); |
127
|
|
|
|
128
|
|
View Code Duplication |
$router->addInternal("500", function () { |
|
|
|
|
129
|
|
|
$this->dispatcher->forward([ |
|
|
|
|
130
|
|
|
"controller" => "error", |
131
|
|
|
"action" => "statusCode", |
132
|
|
|
"params" => [ |
133
|
|
|
"code" => 500, |
134
|
|
|
"message" => "HTTP Status Code 500: There was an internal server or processing error.", |
135
|
|
|
], |
136
|
|
|
]); |
137
|
|
|
})->setName("500"); |
138
|
|
|
|
139
|
|
|
return $router; |
140
|
1 |
|
}); |
141
|
|
|
|
142
|
|
|
$this->setShared("dispatcher", function () { |
143
|
|
|
$dispatcher = new \Anax\MVC\CDispatcherBasic(); |
144
|
|
|
$dispatcher->setDI($this); |
|
|
|
|
145
|
|
|
return $dispatcher; |
146
|
1 |
|
}); |
147
|
|
|
|
148
|
|
|
$this->setShared("session", function () { |
149
|
|
|
$session = new \Anax\Session\CSession(); |
150
|
|
|
$session->configure("session.php"); |
151
|
|
|
$session->name(); |
152
|
|
|
$session->start(); |
153
|
|
|
return $session; |
154
|
1 |
|
}); |
155
|
|
|
|
156
|
|
|
$this->setShared("theme", function () { |
157
|
|
|
$themeEngine = new \Anax\ThemeEngine\CThemeEngine(); |
158
|
|
|
$themeEngine->setDI($this); |
|
|
|
|
159
|
|
|
$themeEngine->configure("theme.php"); |
160
|
|
|
return $themeEngine; |
161
|
1 |
|
}); |
162
|
|
|
|
163
|
|
|
$this->setShared("navbar", function () { |
164
|
|
|
$navbar = new \Anax\Navigation\CNavbar(); |
165
|
|
|
$navbar->setDI($this); |
|
|
|
|
166
|
|
|
$navbar->configure("navbar.php"); |
167
|
|
|
return $navbar; |
168
|
1 |
|
}); |
169
|
|
|
|
170
|
|
|
$this->set("fileContent", function () { |
171
|
|
|
$fc = new \Anax\Content\CFileContent(); |
172
|
|
|
$fc->setDI($this); |
|
|
|
|
173
|
|
|
$fc->configure("file_content.php"); |
174
|
|
|
return $fc; |
175
|
1 |
|
}); |
176
|
|
|
|
177
|
|
|
$this->set("pageContent", function () { |
178
|
|
|
$pc = new \Anax\Content\CPageContent(); |
179
|
|
|
$pc->setDI($this); |
|
|
|
|
180
|
|
|
$pc->configure("page_content.php"); |
181
|
|
|
return $pc; |
182
|
1 |
|
}); |
183
|
|
|
|
184
|
|
|
$this->setShared("content", function () { |
185
|
|
|
$content = new \Anax\Content\CFileBasedContent(); |
186
|
|
|
$content->setDI($this); |
|
|
|
|
187
|
|
|
$content->configure("content.php"); |
188
|
|
|
$content->setDefaultsFromConfiguration(); |
189
|
1 |
|
return $content; |
190
|
|
|
}); |
191
|
1 |
|
|
192
|
|
|
$this->setShared("textFilter", function () { |
193
|
|
|
//$filter = new \Anax\Content\CTextFilter(); |
194
|
|
|
$filter = new \Mos\TextFilter\CTextFilter(); |
195
|
|
|
//$filter->setDI($this); |
196
|
|
|
//$filter->configure(ANAX_APP_PATH . "/config/text_filter.php"); |
197
|
1 |
|
return $filter; |
198
|
1 |
|
}); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: