|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Anax\DI; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* DI factory class creating a set of default services into the DI container. |
|
7
|
|
|
*/ |
|
8
|
|
|
class DIFactoryDefault extends DI |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Constructor creating a set of services included into this DI container. |
|
12
|
|
|
*/ |
|
13
|
2 |
|
public function __construct() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->setShared("request", function () { |
|
16
|
|
|
$request = new \Anax\Request\Request(); |
|
17
|
|
|
$request->init(); |
|
18
|
|
|
return $request; |
|
19
|
2 |
|
}); |
|
20
|
|
|
|
|
21
|
2 |
|
$this->setShared("response", "\Anax\Response\Response"); |
|
22
|
|
|
|
|
23
|
|
View Code Duplication |
$this->setShared("url", function () { |
|
|
|
|
|
|
24
|
|
|
$url = new \Anax\Url\Url(); |
|
25
|
|
|
$request = $this->get("request"); |
|
26
|
|
|
$url->setSiteUrl($request->getSiteUrl()); |
|
27
|
|
|
$url->setBaseUrl($request->getBaseUrl()); |
|
28
|
|
|
$url->setStaticSiteUrl($request->getSiteUrl()); |
|
29
|
|
|
$url->setStaticBaseUrl($request->getBaseUrl()); |
|
30
|
|
|
$url->setScriptName($request->getScriptName()); |
|
31
|
|
|
$url->configure("url.php"); |
|
32
|
|
|
$url->setDefaultsFromConfiguration(); |
|
33
|
|
|
return $url; |
|
34
|
2 |
|
}); |
|
35
|
|
|
|
|
36
|
|
|
$this->setShared("router", function () { |
|
37
|
|
|
$router = new \Anax\Route\Router(); |
|
38
|
|
|
$router->setDI($this); |
|
39
|
|
|
return $router; |
|
40
|
2 |
|
}); |
|
41
|
|
|
|
|
42
|
|
|
$this->setShared("view", function () { |
|
43
|
|
|
$view = new \Anax\View\ViewContainer(); |
|
44
|
|
|
$view->configure("view.php"); |
|
45
|
|
|
$view->setDI($this); |
|
46
|
|
|
return $view; |
|
47
|
2 |
|
}); |
|
48
|
|
|
|
|
49
|
|
|
$this->setShared("viewRenderFile", function () { |
|
50
|
|
|
$viewRender = new \Anax\View\ViewRenderFile2(); |
|
51
|
|
|
$viewRender->setDI($this); |
|
52
|
|
|
return $viewRender; |
|
53
|
2 |
|
}); |
|
54
|
|
|
|
|
55
|
2 |
|
$this->setShared("session", function () { |
|
56
|
|
|
$session = new \Anax\Session\SessionConfigurable(); |
|
57
|
|
|
$session->configure("session.php"); |
|
58
|
|
|
return $session; |
|
59
|
2 |
|
}); |
|
60
|
|
|
|
|
61
|
2 |
|
$this->setShared("textfilter", "\Anax\TextFilter\TextFilter"); |
|
62
|
2 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.