Skip to content

Commit 26bfc05

Browse files
committed
[#.x] - bootstrapping the app in index
1 parent b3d28a1 commit 26bfc05

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

public/index.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,48 @@
22

33
declare(strict_types=1);
44

5-
echo "Hello World!";
5+
use Phalcon\Api\Domain\Services\Container;
6+
use Phalcon\Mvc\Micro;
7+
8+
require_once dirname(__DIR__) . '/vendor/autoload.php';
9+
10+
$container = new Container();
11+
$application = new Micro($container);
12+
13+
/**
14+
* Routes
15+
*/
16+
$routes = [
17+
[
18+
'method' => 'get',
19+
'pattern' => '/',
20+
'handler' => Container::HELLO_ACTION,
21+
],
22+
];
23+
24+
foreach ($routes as $route) {
25+
$method = $route['method'];
26+
$pattern = $route['pattern'];
27+
$handler = $route['handler'];
28+
29+
$application->$method(
30+
$pattern,
31+
function () use ($container, $handler) {
32+
$action = $container->get($handler);
33+
34+
$action();
35+
}
36+
);
37+
}
38+
39+
$application->notFound(
40+
function () {
41+
echo "404 - Not Found - " . date("Y-m-d H:i:s");
42+
}
43+
);
44+
45+
46+
/** @var string $uri */
47+
$uri = $_SERVER['REQUEST_URI'] ?? '';
48+
49+
$application->handle($uri);

0 commit comments

Comments
 (0)