-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
71 lines (58 loc) · 1.9 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
* This file is part of the PHALCON-EXT package.
*
* (c) Jitendra Adhikari <[email protected]>
* <https://github.com/adhocore>
*
* Licensed under MIT license.
*/
use Phalcon\Mvc\Micro as MicroApplication;
use Phalcon\Mvc\Micro\Collection;
use Phalcon\Mvc\Router;
use Phalcon\Mvc\View\Simple as SimpleView;
use PhalconExt\Example\MicroController;
use PhalconExt\Http\Middleware\ApiAuth;
use PhalconExt\Http\Middleware\Cache;
use PhalconExt\Http\Middleware\Cors;
use PhalconExt\Http\Middleware\Throttle;
use PhalconExt\Http\Middlewares;
// Micro app
// In micro mode, most of the di services are the same
$di = require __DIR__ . '/bootstrap.php';
// However we will use simple view here
$di->setShared('view', function () {
$view = new SimpleView;
$view->setViewsDir($this->get('config')->toArray()['view']['dir']);
$view->registerEngines([
'.twig' => 'twig',
]);
return $view;
});
$app = new MicroApplication($di);
$app->getRouter()->setUriSource(Router::URI_SOURCE_GET_URL);
$app->mount(
(new Collection)
->setPrefix('/')
->setHandler(MicroController::class, true)
->get('/', 'indexAction', 'home')
->get('db', 'dbAction')
->get('di', 'diAction')
->get('mail', 'mailAction')
->get('logger', 'loggerAction')
->get('validation', 'validationAction')
->get('cors', 'corsAction')
// Need to allow OPTIONS request for cors enabled endpoint!
// (But not always, simple requests can do without it.)
->options('corsheader', 'corsHeaderAction')
->get('corsheader', 'corsHeaderAction')
->post('api/auth', 'authAction')
);
$app->notFound(function () use ($di) {
return $di->get('response')->setContent('404 Not Found')->setStatusCode(404);
});
// For test return the app instance
if (getenv('APP_ENV') === 'test') {
return $app;
}
(new Middlewares([Throttle::class, ApiAuth::class, Cors::class, Cache::class]))->wrap($app);