SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | // app/boot.php | |
| 3 | require_once __DIR__.'/../vendor/autoload.php'; | |
| 4 | ||
| 5 | define('__BASE__', realpath(__DIR__.'/..'));
| |
| 6 | define('__APP__', __DIR__);
| |
| 7 | define('__WEB__', realpath(__DIR__.'/../web'));
| |
| 8 | define('__SRC__', realpath(__DIR__.'/../src'));
| |
| 9 | define('__VENDOR__', realpath(__DIR__.'/../vendor'));
| |
| 10 | ||
| 11 | $app = new App\Application(); | |
| 12 | ||
| 13 | return $app; | |
| 14 | ||
| 15 | // app/routes.php | |
| 16 | // helper function (https://igor.io/2012/11/09/scaling-silex.html) | |
| 17 | function controller($shortName) | |
| 18 | {
| |
| 19 | list($shortClass, $shortMethod) = explode('/', $shortName, 2);
| |
| 20 | ||
| 21 | return sprintf('App\Controller\%sController::%sAction', ucfirst($shortClass), $shortMethod);
| |
| 22 | } | |
| 23 | ||
| 24 | $app->get('/', controller('home/index'))->secure('IS_AUTHENTICATED_FULLY')->bind('home');
| |
| 25 | $app->get('/login', controller('auth/login'))->bind('login');
| |
| 26 | ||
| 27 | if (!$app['debug']) {
| |
| 28 | $app->error(function (Exception $e, $code) use ($app) {
| |
| 29 | $app['monolog']->addError($e->getMessage()); | |
| 30 | $app['monolog']->addError($e->getTraceAsString()); | |
| 31 | ||
| 32 | try {
| |
| 33 | $template = 'error/' . $code . '.html.twig'; | |
| 34 | ||
| 35 | return $app['twig']->render($template, array( | |
| 36 | 'code' => $code, | |
| 37 | 'exception' => $e, | |
| 38 | )); | |
| 39 | } catch (Exception $ex) {
| |
| 40 | try {
| |
| 41 | $template = 'error/index.html.twig'; | |
| 42 | ||
| 43 | return $app['twig']->render($template, array( | |
| 44 | 'code' => $code, | |
| 45 | 'exception' => $e, | |
| 46 | )); | |
| 47 | } catch (Exception $ex) {
| |
| 48 | return $code . ' - ' . $e->getMessage(); | |
| 49 | } | |
| 50 | } | |
| 51 | }); | |
| 52 | } | |
| 53 | ||
| 54 | // Server | |
| 55 | $server = $app['controllers_factory']; | |
| 56 | ||
| 57 | $server->get('/', controller('server/index'));
| |
| 58 | $server->get('/start', controller('server/start'))->secure('ROLE_SERVER_START')->bind('server_start');
| |
| 59 | $server->get('/stop', controller('server/stop'))->secure('ROLE_SERVER_STOP')->bind('server_stop');
| |
| 60 | $server->get('/restart', controller('server/restart'))->secure('ROLE_SERVER_RESTART')->bind('server_restart');
| |
| 61 | ||
| 62 | $app->mount('/server', $server);
| |
| 63 | ||
| 64 | - | $api = $app['controllers_factory']; |
| 64 | + | // API |
| 65 | /*$api = $app['controllers_factory']; | |
| 66 | ||
| 67 | $api->get('/status', function () use ($app) {
| |
| 68 | - | 'status' => $app['system']->isRunning() ? 'running' : 'stopped', |
| 68 | + | |
| 69 | 'status' => $app['server']->isRunning() ? 'running' : 'stopped', | |
| 70 | )); | |
| 71 | }); | |
| 72 | - | $app->mount('/api/v1', $api);
|
| 72 | + | |
| 73 | $app->mount('/api/v1', $api);*/
| |
| 74 | ||
| 75 | // User | |
| 76 | $user = $app['controllers_factory']; | |
| 77 | ||
| 78 | $user->get('/', controller('user/index'))->secure('ROLE_USER_VIEW')->bind('user');
| |
| 79 | $user->get('/add', controller('user/add'))->secure('ROLE_USER_ADD')->bind('user_add');
| |
| 80 | $user->post('/add', controller('user/add'))->secure('ROLE_USER_ADD');
| |
| 81 | $user->get('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT')->bind('user_edit');
| |
| 82 | $user->post('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT');
| |
| 83 | $user->get('/delete/{username}', controller('user/delete'))->secure('ROLE_USER_DELETE')->bind('user_delete');
| |
| 84 | ||
| 85 | $app->mount('/user', $user);
| |
| 86 | ||
| 87 | ||
| 88 | // User | |
| 89 | $user = $app['controllers_factory']; | |
| 90 | ||
| 91 | $user->get('/', controller('user/index'))->secure('ROLE_USER_VIEW')->bind('user');
| |
| 92 | $user->get('/add', controller('user/add'))->secure('ROLE_USER_ADD')->bind('user_add');
| |
| 93 | $user->post('/add', controller('user/add'))->secure('ROLE_USER_ADD');
| |
| 94 | $user->get('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT')->bind('user_edit');
| |
| 95 | $user->post('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT');
| |
| 96 | $user->get('/delete/{username}', controller('user/delete'))->secure('ROLE_USER_DELETE')->bind('user_delete');
| |
| 97 | ||
| 98 | $app->mount('/user', $user);
| |
| 99 | ||
| 100 | // web/index.php | |
| 101 | $app = require_once __DIR__.'/../app/boot.php'; | |
| 102 | ||
| 103 | require_once __DIR__.'/../app/routes.php'; | |
| 104 | ||
| 105 | $app->run(); |