forked from ezimuel/zend-expressive-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
38 lines (30 loc) · 1.18 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
use Zend\Expressive\Application;
use Zend\Expressive\Helper\BodyParams\BodyParamsMiddleware;
use Zend\Expressive\Helper\UrlHelperMiddleware;
use App\Middleware;
// Delegate static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server'
&& is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))
) {
return false;
}
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
/** @var \Interop\Container\ContainerInterface $container */
$container = require 'config/container.php';
/** @var \Zend\Expressive\Application $app */
$app = $container->get(Application::class);
$app->pipe(BodyParamsMiddleware::class);
$app->pipeRoutingMiddleware();
$app->pipe(UrlHelperMiddleware::class);
$app->pipeDispatchMiddleware();
// Routes
$app->get('/api/ping', Middleware\Ping::class, 'api.ping');
$app->get('/api/user[/{id:\d+}]', Middleware\User::class, 'api.user.get');
$app->post('/api/user', Middleware\User::class, 'api.user.post');
$app->patch('/api/user/{id:\d+}', Middleware\User::class, 'api.user.patch');
$app->delete('/api/user/{id:\d+}', Middleware\User::class, 'api.user.delete');
$app->run();