|
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) { |
|
|
|
|
|
|
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
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.