/**
  * Generic error handler for application. Note that this will _not_ catch PHP errors, those are handled via
  * App\Core\ExceptionHandler class which extends base Symfony ExceptionHandler class.
  *
  * @param   \Exception  $exception
  * @param   integer     $status
  *
  * @return  \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function error(\Exception $exception, $status)
 {
     // Basic error data
     $error = ['message' => $exception->getMessage(), 'status' => $status, 'code' => $exception->getCode()];
     // If we're running application in debug mode, attach some extra information about actual error
     if ($this->app['debug']) {
         $error += ['debug' => ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace(), 'traceString' => $exception->getTraceAsString()]];
     }
     // And return JSON output
     return $this->app->json($error, $status);
 }
Example #2
0
 public function tracksAction(Application $app, Request $reqeust)
 {
     $sellers = $app['track.model']->findWithMetadata();
     $data = [];
     //        $data = ['tracks' => $sellers->getIterator()];
     //  print_r($sellers);
     //phpinfo();
     return $app->json($sellers);
     //$app->render('project.twig', $data);
 }
Example #3
0
 public function loadRoutes(Application $app)
 {
     $app['home.controller'] = function () use($app) {
         return new Controller\HomeController();
     };
     $app->mount('/admin', new Controller\Admin\BlogController());
     $app->get('/test/rr', "home.controller:test");
     $app->get('/', "home.controller:indexAction");
     $app->get('/record', "home.controller:record");
     $app->get('/test2', "home.controller:test2")->method('get|post');
     $app->get('/tracks', "home.controller:tracksAction");
     $app->get('/one/', function () use($app) {
         return $app->json(['a' => 'b']);
     })->bind('sidebar');
     $app->get('/admin/login', function (Request $request) use($app) {
         return $app['twig']->render('admin/login.twig', ['error' => $app['security.last_error']($request), 'last_username' => $app['session']->get('_security.last_username')]);
     });
     $app->get('/admin/', function () use($app) {
         return 'admin';
     });
     /**
      * редирект для всех несуществующих роутов в админку
      */
     $app->get('/admin/{all}', function () use($app) {
         return $app->redirect('/admin/');
     })->assert('all', '.*');
     $app['security.firewalls'] = ['login' => ['pattern' => '^/admin/login$'], 'secured_area' => ['pattern' => '^/admin', 'form' => ['login_path' => '/admin/login', 'check_path' => '/admin/check_login', 'always_use_default_target_path' => true, 'default_target_path' => 'post'], 'logout' => ['logout_path' => '/admin/logout', 'target' => '/', 'invalidate_session' => true], 'users' => ['admin' => ['ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==']]]];
 }
Example #4
0
 public function delete(Application $app, Request $request)
 {
     $item_id = $request->get('item_id');
     $app->oauth->delete($item_id);
     return $app->json(true);
 }