Completed
Push — dev-master ( 1290b8...c91af7 )
by Derek Stephen
07:37
created

TestPackage::addRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BoneMvc\Module\Test;
6
7
use Barnacle\Container;
8
use Barnacle\RegistrationInterface;
9
use BoneMvc\Mail\Service\MailService;
10
use BoneMvc\Module\Test\Controller\TestApiController;
11
use BoneMvc\Module\Test\Controller\TestController;
12
use Bone\Mvc\Router\RouterConfigInterface;
13
use Bone\Mvc\View\PlatesEngine;
14
use League\Route\RouteGroup;
15
use League\Route\Router;
16
use League\Route\Strategy\JsonStrategy;
17
use Zend\Diactoros\ResponseFactory;
18
19
class TestPackage implements RegistrationInterface, RouterConfigInterface
20
{
21
    /**
22
     * @param Container $c
23
     */
24
    public function addToContainer(Container $c)
25
    {
26
        /** @var PlatesEngine $viewEngine */
27
        $viewEngine = $c->get(PlatesEngine::class);
28
        $viewEngine->addFolder('test', __DIR__ . '/View/Test/');
29
        $viewEngine->addFolder('testemails', __DIR__ . '/View/emails/');
30
31
        $c[TestController::class] = $c->factory(function (Container $c) {
32
            /** @var PlatesEngine $viewEngine */
33
            $viewEngine = $c->get(PlatesEngine::class);
34
35
            /** @var MailService $mailService */
36
            $mailService = $c->get(MailService::class);
37
38
            return new TestController($viewEngine, $mailService);
39
        });
40
41
        $c[TestApiController::class] = $c->factory(function (Container $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
            return new TestApiController();
43
        });
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getEntityPath(): string
50
    {
51
        return '';
52
    }
53
54
    /**
55
     * @return bool
56
     */
57
    public function hasEntityPath(): bool
58
    {
59
        return false;
60
    }
61
62
    /**
63
     * @param Container $c
64
     * @param Router $router
65
     * @return Router
66
     */
67
    public function addRoutes(Container $c, Router $router): Router
68
    {
69
        $router->map('GET', '/test', [TestController::class, 'indexAction']);
70
71
        $factory = new ResponseFactory();
72
        $strategy = new JsonStrategy($factory);
73
        $strategy->setContainer($c);
74
75
        $router->group('/api', function (RouteGroup $route) {
76
            $route->map('GET', '/test', [TestApiController::class, 'indexAction']);
77
        })
78
        ->setStrategy($strategy);
79
80
        return $router;
81
    }
82
}
83