Guest User

Untitled

a guest
Jan 3rd, 2014
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.05 KB | None | 0 0
  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'];
  65.  
  66. $api->get('/status', function () use ($app) {
  67.     return new Symfony\Component\HttpFoundation\JsonResponse(array(
  68.         'status' => $app['system']->isRunning() ? 'running' : 'stopped',
  69.     ));
  70. });
  71.  
  72. $app->mount('/api/v1', $api);
  73.  
  74. // User
  75. $user = $app['controllers_factory'];
  76.  
  77. $user->get('/', controller('user/index'))->secure('ROLE_USER_VIEW')->bind('user');
  78. $user->get('/add', controller('user/add'))->secure('ROLE_USER_ADD')->bind('user_add');
  79. $user->post('/add', controller('user/add'))->secure('ROLE_USER_ADD');
  80. $user->get('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT')->bind('user_edit');
  81. $user->post('/edit/{username}', controller('user/edit'))->secure('ROLE_USER_EDIT');
  82. $user->get('/delete/{username}', controller('user/delete'))->secure('ROLE_USER_DELETE')->bind('user_delete');
  83.  
  84. $app->mount('/user', $user);
  85.  
  86. // web/index.php
  87. $app = require_once __DIR__.'/../app/boot.php';
  88.  
  89. require_once __DIR__.'/../app/routes.php';
  90.  
  91. $app->run();
Advertisement
Add Comment
Please, Sign In to add comment