Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // app/boot.php
- require_once __DIR__.'/../vendor/autoload.php';
- define('__BASE__', realpath(__DIR__.'/..'));
- define('__APP__', __DIR__);
- define('__WEB__', realpath(__DIR__.'/../web'));
- define('__SRC__', realpath(__DIR__.'/../src'));
- define('__VENDOR__', realpath(__DIR__.'/../vendor'));
- $app = new App\Application();
- return $app;
- // app/routes.php
- // helper function (https://igor.io/2012/11/09/scaling-silex.html)
- function controller($shortName)
- {
- list($shortClass, $shortMethod) = explode('/', $shortName, 2);
- return sprintf('App\Controller\%sController::%sAction', ucfirst($shortClass), $shortMethod);
- }
- $app->get('/', controller('home/index'))->secure('IS_AUTHENTICATED_FULLY')->bind('home');
- $app->get('/login', controller('auth/login'))->bind('login');
- if (!$app['debug']) {
- $app->error(function (Exception $e, $code) use ($app) {
- $app['monolog']->addError($e->getMessage());
- $app['monolog']->addError($e->getTraceAsString());
- try {
- $template = 'error/' . $code . '.html.twig';
- return $app['twig']->render($template, array(
- 'code' => $code,
- 'exception' => $e,
- ));
- } catch (Exception $ex) {
- try {
- $template = 'error/index.html.twig';
- return $app['twig']->render($template, array(
- 'code' => $code,
- 'exception' => $e,
- ));
- } catch (Exception $ex) {
- return $code . ' - ' . $e->getMessage();
- }
- }
- });
- }
- // Server
- $server = $app['controllers_factory'];
- $server->get('/', controller('server/index'));
- $server->get('/start', controller('server/start'))->secure('ROLE_SERVER_START')->bind('server_start');
- $server->get('/stop', controller('server/stop'))->secure('ROLE_SERVER_STOP')->bind('server_stop');
- $server->get('/restart', controller('server/restart'))->secure('ROLE_SERVER_RESTART')->bind('server_restart');
- $app->mount('/server', $server);
- // API
- /*$api = $app['controllers_factory'];
- $api->get('/status', function () use ($app) {
- return new Symfony\Component\HttpFoundation\JsonResponse(array(
- 'status' => $app['server']->isRunning() ? 'running' : 'stopped',
- ));
- });
- $app->mount('/api/v1', $api);*/
- // User
- $user = $app['controllers_factory'];
- $user->get('/', controller('user/index'))->secure('ROLE_USER_VIEW')->bind('user');
- $user->get('/add', controller('user/add'))->secure('ROLE_USER_ADD')->bind('user_add');
- $user->post('/add', controller('user/add'))->secure('ROLE_USER_ADD');
- $user->get('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT')->bind('user_edit');
- $user->post('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT');
- $user->get('/delete/{username}', controller('user/delete'))->secure('ROLE_USER_DELETE')->bind('user_delete');
- $app->mount('/user', $user);
- // User
- $user = $app['controllers_factory'];
- $user->get('/', controller('user/index'))->secure('ROLE_USER_VIEW')->bind('user');
- $user->get('/add', controller('user/add'))->secure('ROLE_USER_ADD')->bind('user_add');
- $user->post('/add', controller('user/add'))->secure('ROLE_USER_ADD');
- $user->get('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT')->bind('user_edit');
- $user->post('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT');
- $user->get('/delete/{username}', controller('user/delete'))->secure('ROLE_USER_DELETE')->bind('user_delete');
- $app->mount('/user', $user);
- // web/index.php
- $app = require_once __DIR__.'/../app/boot.php';
- require_once __DIR__.'/../app/routes.php';
- $app->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement