Skip to content

Commit 243e081

Browse files
committed
[#.x] - adjustments to use the new services
1 parent 681b912 commit 243e081

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

public/index.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
declare(strict_types=1);
44

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;
59
use Phalcon\Api\Domain\Services\Container;
610
use Phalcon\Mvc\Micro;
711

@@ -15,27 +19,42 @@
1519
*/
1620
$routes = [
1721
[
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,
2126
],
2227
];
2328

2429
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'];
2834

2935
$application->$method(
3036
$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);
3342

34-
$action();
43+
$action = new ActionHandler($service, $responder);
44+
$action->__invoke();
3545
}
3646
);
3747
}
3848

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+
3958
$application->notFound(
4059
function () {
4160
echo "404 - Not Found - " . date("Y-m-d H:i:s");

0 commit comments

Comments
 (0)