Passed
Push — master ( 42dea4...54c542 )
by Mikael
01:37
created

DIFactoryDefault   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 28.75%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 125
ccs 23
cts 80
cp 0.2875
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 114 1
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 DIFactoryDefault extends DI
10
{
11
    //use \Anax\TLoadFile;
12
13
14
15
   /**
16
     * Construct.
17
     *
18
     */
19 1
    public function __construct()
20
    {
21
        //parent::__construct();
22
23
        //$this->loadFile("error_reporting.php");
24
25 1
        $this->setShared("response", "\Anax\Response\CResponseBasic");
26 1
        $this->setShared("validate", "\Anax\Validate\CValidate");
27 1
        $this->setShared("flash", "\Anax\Flash\CFlashBasic");
28 1
        $this->setShared("textFilter", "\Mos\TextFilter\CTextFilter");
29
30 1
        $this->set("route", "\Anax\Route\CRouteBasic");
31 1
        $this->set("view", "\Anax\View\CView");
32
33
        $this->set("ErrorController", function () {
34
            $controller = new \Anax\MVC\ErrorController();
35
            $controller->setDI($this);
36
            return $controller;
37 1
        });
38
39
        $this->setShared("log", function () {
40
            $log = new \Anax\Log\CLogger();
41
            $log->setContext("development");
42
            return $log;
43 1
        });
44
45
        $this->setShared("cache", function () {
46
            $cache = new \Anax\Cache\CFileCache();
47
            $cache->configure("cache.php");
48
            return $cache;
49 1
        });
50
51
        $this->setShared("request", function () {
52
            $request = new \Anax\Request\CRequestBasic();
53
            $request->init();
54
            return $request;
55 1
        });
56
57
        $this->setShared("url", function () {
58
            $url = new \Anax\Url\CUrl();
59
            $url->configure("url.php");
60
            $url->setSiteUrl($this->request->getSiteUrl());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\DIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
61
            $url->setBaseUrl($this->request->getBaseUrl());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\DIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
62
            $url->setStaticSiteUrl($this->request->getSiteUrl());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\DIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
63
            $url->setStaticBaseUrl($this->request->getBaseUrl());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\DIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
64
            $url->setScriptName($this->request->getScriptName());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\DIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
65
            $url->setDefaultsFromConfiguration();
66
            return $url;
67 1
        });
68
69
        $this->setShared("views", function () {
70
            $views = new \Anax\View\CViewContainer();
71
            $views->configure("views.php");
72
            $views->setDI($this);
73
            return $views;
74 1
        });
75
76
        $this->setShared("router", function () {
77
            
78
            $router = new \Anax\Route\CRouterBasic();
79
            $router->setDI($this);
80
            return $router;
81 1
        });
82
83
        $this->setShared("dispatcher", function () {
84
            $dispatcher = new \Anax\MVC\CDispatcherBasic();
85
            $dispatcher->setDI($this);
86
            return $dispatcher;
87 1
        });
88
89
        $this->setShared("session", function () {
90
            $session = new \Anax\Session\CSession();
91
            $session->configure("session.php");
92
            $session->name();
93
            $session->start();
94
            return $session;
95 1
        });
96
97
        $this->setShared("theme", function () {
98
            $themeEngine = new \Anax\ThemeEngine\CThemeEngine();
99
            $themeEngine->setDI($this);
100
            $themeEngine->configure("theme.php");
101
            return $themeEngine;
102 1
        });
103
104
        $this->setShared("navbar", function () {
105
            $navbar = new \Anax\Navigation\CNavbar();
106
            $navbar->setDI($this);
107
            $navbar->configure("navbar.php");
108
            return $navbar;
109 1
        });
110
111
        $this->set("fileContent", function () {
112
            $fc = new \Anax\Content\CFileContent();
113
            $fc->setDI($this);
114
            $fc->configure("file_content.php");
115
            return $fc;
116 1
        });
117
118
        $this->set("pageContent", function () {
119
            $pc = new \Anax\Content\CPageContent();
120
            $pc->setDI($this);
121
            $pc->configure("page_content.php");
122
            return $pc;
123 1
        });
124
125 1
        $this->setShared("content", function () {
126
            $content = new \Anax\Content\CFileBasedContent();
127
            $content->setDI($this);
128
            $content->configure("content.php");
129
            $content->setDefaultsFromConfiguration();
130
            return $content;
131 1
        });
132 1
    }
133
}
134