Completed
Push — master ( 0a1e54...e4fe66 )
by Derek Stephen
02:58
created

RouterPackage::getEntityPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bone\Router;
6
7
use Barnacle\Container;
8
use Barnacle\RegistrationInterface;
9
use Bone\Router\Router;
10
use Bone\Router\Decorator\ExceptionDecorator;
11
use Bone\Router\Decorator\NotAllowedDecorator;
12
use Bone\Router\Decorator\NotFoundDecorator;
13
use Bone\Router\PlatesStrategy;
14
use Bone\View\ViewEngine;
15
16
class RouterPackage implements RegistrationInterface
17
{
18
    /**
19
     * @param Container $c
20
     */
21
    public function addToContainer(Container $c)
22
    {
23
        $c[ViewEngine::class] = $c->get(ViewEngine::class);
24
25
        $c[NotFoundDecorator::class] = $c->factory(function (Container $c) {
26
            $layout = $c->get('default_layout');
27
            $templates = $c->get('error_pages');
28
            $viewEngine = $c->get(ViewEngine::class);
29
            $notFoundDecorator = new NotFoundDecorator($viewEngine, $templates);
30
            $notFoundDecorator->setLayout($layout);
31
32
            return $notFoundDecorator;
33
        });
34
35
        $c[NotAllowedDecorator::class] = $c->factory(function (Container $c) {
36
            $layout = $c->get('default_layout');
37
            $templates = $c->get('error_pages');
38
            $viewEngine = $c->get(ViewEngine::class);
39
            $notAllowedDecorator = new NotAllowedDecorator($viewEngine, $templates);
40
            $notAllowedDecorator->setLayout($layout);
41
42
            return $notAllowedDecorator;
43
        });
44
45
        $c[ExceptionDecorator::class] = $c->factory(function (Container $c) {
46
            $viewEngine = $c->get(ViewEngine::class);
47
            $layout = $c->get('default_layout');
48
            $templates = $c->get('error_pages');
49
            $decorator = new ExceptionDecorator($viewEngine, $templates);
50
            $decorator->setLayout($layout);
51
52
            return $decorator;
53
        });
54
55
        $c[PlatesStrategy::class] = $c->factory(function (Container $c) {
56
            $viewEngine = $c->get(ViewEngine::class);
57
            $notFoundDecorator = $c->get(NotFoundDecorator::class);
58
            $notAllowedDecorator = $c->get(NotAllowedDecorator::class);
59
            $exceptionDecorator = $c->get(ExceptionDecorator::class);
60
            $layout = $c->get('default_layout');
61
            $strategy = new PlatesStrategy($viewEngine, $notFoundDecorator, $notAllowedDecorator, $layout, $exceptionDecorator);
62
63
            return $strategy;
64
        });
65
66
        /** @var PlatesStrategy $strategy */
67
        $strategy = $c->get(PlatesStrategy::class);
68
        $strategy->setContainer($c);
69
70
        $router = $c->get(Router::class);
71
        $router->setStrategy($strategy);
72
    }
73
}
74