|
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
| 5 | +use Phalcon\Api\Domain\Interfaces\DomainInterface; |
| 6 | +use Phalcon\Api\Domain\Interfaces\ResponderInterface; |
| 7 | +use Phalcon\Api\Domain\Middleware\ResponseSender; |
| 8 | +use Phalcon\Api\Domain\Services\ActionHandler; |
5 | 9 | use Phalcon\Api\Domain\Services\Container; |
6 | 10 | use Phalcon\Mvc\Micro; |
7 | 11 |
|
|
15 | 19 | */ |
16 | 20 | $routes = [ |
17 | 21 | [ |
18 | | - 'method' => 'get', |
19 | | - 'pattern' => '/', |
20 | | - 'handler' => Container::HELLO_ACTION, |
| 22 | + 'method' => 'get', |
| 23 | + 'pattern' => '/', |
| 24 | + 'service' => Container::HELLO_SERVICE, |
| 25 | + 'responder' => Container::HELLO_RESPONDER_JSON, |
21 | 26 | ], |
22 | 27 | ]; |
23 | 28 |
|
24 | 29 | foreach ($routes as $route) { |
25 | | - $method = $route['method']; |
26 | | - $pattern = $route['pattern']; |
27 | | - $handler = $route['handler']; |
| 30 | + $method = $route['method']; |
| 31 | + $pattern = $route['pattern']; |
| 32 | + $serviceName = $route['service']; |
| 33 | + $responderName = $route['responder']; |
28 | 34 |
|
29 | 35 | $application->$method( |
30 | 36 | $pattern, |
31 | | - function () use ($container, $handler) { |
32 | | - $action = $container->get($handler); |
| 37 | + function () use ($container, $serviceName, $responderName) { |
| 38 | + /** @var DomainInterface $service */ |
| 39 | + $service = $container->get($serviceName); |
| 40 | + /** @var ResponderInterface $responder */ |
| 41 | + $responder = $container->get($responderName); |
33 | 42 |
|
34 | | - $action(); |
| 43 | + $action = new ActionHandler($service, $responder); |
| 44 | + $action->__invoke(); |
35 | 45 | } |
36 | 46 | ); |
37 | 47 | } |
38 | 48 |
|
| 49 | +$application->finish( |
| 50 | + function () use ($container) { |
| 51 | + $response = $container->getShared(Container::RESPONSE); |
| 52 | + $sender = new ResponseSender(); |
| 53 | + |
| 54 | + $sender->__invoke($response); |
| 55 | + } |
| 56 | +); |
| 57 | + |
39 | 58 | $application->notFound( |
40 | 59 | function () { |
41 | 60 | echo "404 - Not Found - " . date("Y-m-d H:i:s"); |
|
0 commit comments