Ejemplo n.º 1
0
 /**
  * Returns routes to connect to the given application.
  *
  * @param   App $app    An Application instance
  *
  * @return  ControllerCollection    A ControllerCollection instance
  */
 public function connect(App $app)
 {
     // Store application
     $this->app = $app;
     // Set error handling globally
     $this->app->error([$this, 'error']);
     /**
      * Get application current controllers
      *
      * @var ControllerCollection $controllers
      */
     $controllers = $this->app['controllers_factory'];
     // Mount controllers to specified routes.
     $this->mount();
     return $controllers;
 }
Ejemplo n.º 2
0
 public function loadErrorHandler(Application $app)
 {
     $app->error(function (HttpException $e) use($app) {
         $errCode = $e->getStatusCode();
         $data = ['code' => $errCode, 'status' => 'error', 'message' => $e->getMessage(), 'data' => $e->getHeaders()];
         //            $headers['Content-Type'] = 'application/json; charset=UTF-8';
         return new JsonResponse($data, $errCode);
     }, 1000);
     $app->error(function (\Exception $e) use($app) {
         throw $e;
     });
 }