當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Application::error方法代碼示例

本文整理匯總了PHP中Silex\Application::error方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::error方法的具體用法?PHP Application::error怎麽用?PHP Application::error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Silex\Application的用法示例。


在下文中一共展示了Application::error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: register

 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Application $app
  */
 public function register(Application $app)
 {
     $app['error.controller'] = $controller = new ErrorController($app);
     $app->error([$controller, 'onApiProblemException']);
     $app->error([$controller, 'whenNotFound']);
     $app->error([$controller, 'whenNotAllowed']);
     $app->error([$controller, 'onHttpException']);
     $app->error([$controller, 'onGeneralException']);
 }
開發者ID:pdziok,項目名稱:hackday-project,代碼行數:17,代碼來源:ErrorControllerServiceProvider.php

示例2: setupErrorHandlers

 /**
  * Setup error handlers
  */
 protected function setupErrorHandlers()
 {
     $this->app->error(function (\Exception $e, $code) {
         $data = array('status' => $code);
         if ($this->app['config']('app.debug', false)) {
             $data['error'] = $e->getMessage();
         }
         return $this->app->json($data, $code);
     });
 }
開發者ID:skymeyer,項目名稱:csp-report-collector,代碼行數:13,代碼來源:Application.php

示例3: register

 /**
  * @inheritdoc
  */
 public function register(Application $app)
 {
     $provider = $this;
     $app->error(function (ValidationException $e) use($provider) {
         $problem = new ApiProblem($e->getMessage());
         $problem['validation_messages'] = $e->getErrors();
         return $provider->createBadRequestResponse($problem);
     });
     $app->error(function (InvalidNativeArgumentException $e) use($provider) {
         $problem = new ApiProblem($e->getMessage());
         return $provider->createBadRequestResponse($problem);
     });
 }
開發者ID:Axxon,項目名稱:udb3-silex,代碼行數:16,代碼來源:ErrorHandlerProvider.php

示例4: defineErrorHandler

 /**
  * Define error handler
  */
 private function defineErrorHandler()
 {
     $this->app->error(function (\Exception $e, $code) {
         if ($this->app['debug']) {
             return null;
         }
         switch ($code) {
             case 404:
                 return ResponseBuilder::createErrorResponse($this->app, ResponseBuilder::STATUS_TYPE_ROUTE_NOT_FOUND, $e->getMessage(), $code);
             default:
                 return ResponseBuilder::createErrorResponse($this->app, ResponseBuilder::STATUS_TYPE_ERROR, $e->getMessage(), $code);
         }
     });
 }
開發者ID:triadev,項目名稱:service-user-manager,代碼行數:17,代碼來源:Router.php

示例5: boot

 public function boot(Application $app)
 {
     $app->error(function (Exception $e) use($app) {
         $app['logger']->addError($e->getMessage());
         return new Response($e->getMessage());
     });
 }
開發者ID:RepoMon,項目名稱:update,代碼行數:7,代碼來源:ErrorHandler.php

示例6: __construct

 public function __construct(array $config = array())
 {
     parent::__construct($config);
     parent::error(function (\Exception $e, $code) {
         return parent::json(array("error" => $e->getMessage()), $code);
     });
 }
開發者ID:krlitus,項目名稱:doctrine,代碼行數:7,代碼來源:App.php

示例7: connect

 public function connect(Application $app)
 {
     $route = $app['controllers_factory'];
     $route->get('/', function (Application $app, Request $request) {
         return $app['mh.controllers.base']->index($request);
     });
     $route->post('/guest', function (Application $app, Request $request) {
         return $app['mh.controllers.guest']->find($request);
     });
     $route->get('/pay/{id}', function (Application $app, Request $request, $id) {
         return $app['mh.controllers.guest']->payment($id);
     });
     $route->post('/process/{id}', function (Application $app, Request $request, $id) {
         return $app['mh.controllers.transaction']->pay($request, $id);
     });
     $route->get('/not-found', function (Application $app) {
         return $app['mh.controllers.guest']->notFound();
     });
     $route->get('/thank-you', function (Application $app) {
         return $app['mh.controllers.guest']->thanks();
     });
     $app->error(function (\Exception $e, $code) {
         if (404 == $code) {
             return new Response('', 301, ['location' => '/']);
         }
     });
     return $route;
 }
開發者ID:jdpedrie,項目名稱:manandham.com,代碼行數:28,代碼來源:RouteProvider.php

示例8: boot

 public function boot(\Silex\Application $app)
 {
     $app->before(function (\Symfony\Component\HttpFoundation\Request $request) use($app) {
         $routeName = $request->attributes->get('_route');
         $route = $request->getRequestUri();
         $log = $_SERVER['REMOTE_ADDR'] . ' - ';
         if ($app['session']->has('user') && defined('USERNAME_METHOD_LOGGED')) {
             $user = $app['session']->get('user');
             $method = USERNAME_METHOD_LOGGED;
             if (is_callable(array($user, $method))) {
                 $name = $user->{$method}();
                 if (!empty($name)) {
                     $log .= $name;
                 }
             }
         }
         if (!empty($routeName)) {
             $log .= ' está acessando a rota "' . $routeName . '" (' . $route . ')';
         } else {
             if (!file_exists(__WEBROOT__ . $route)) {
                 $log .= ' tentou acessar um arquivo ou rota inexistente (' . $route . ')!';
             } else {
                 $log .= ' está acessando um arquivo (' . $route . ')!';
             }
         }
         $app['monolog']->addInfo($log);
     });
     $app->error(function (\Exception $e, $code) use($app) {
         $msg = $code != 500 ? $e->getMessage() : $e->getFile() . ' na linha ' . $e->getLine() . ': ' . $e->getMessage();
         $app['monolog']->addError('cod: ' . $code . ' => ' . $msg);
     });
 }
開發者ID:mlalbuquerque,項目名稱:silex-skeleton,代碼行數:32,代碼來源:LoggerServiceProvider.php

示例9: boot

 public function boot(Application $app)
 {
     $app->before(function (Request $request) use($app) {
         $app['monolog']->addInfo('> ' . $request->getMethod() . ' ' . $request->getRequestUri());
     });
     /*
      * Priority -4 is used to come after those from SecurityServiceProvider (0)
      * but before the error handlers added with Silex\Application::error (defaults to -8)
      */
     $app->error(function (\Exception $e) use($app) {
         $message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
         if ($e instanceof HttpExceptionInterface && $e->getStatusCode() < 500) {
             $app['monolog']->addError($message, array('exception' => $e));
         } else {
             $app['monolog']->addCritical($message, array('exception' => $e));
         }
     }, -4);
     $app->after(function (Request $request, Response $response) use($app) {
         if ($response instanceof RedirectResponse) {
             $app['monolog']->addInfo('< ' . $response->getStatusCode() . ' ' . $response->getTargetUrl());
         } else {
             $app['monolog']->addInfo('< ' . $response->getStatusCode());
         }
     });
 }
開發者ID:robihidayat,項目名稱:silex-mongodb-parks,代碼行數:25,代碼來源:MonologServiceProvider.php

示例10: testRegisterAndRender

 public function testRegisterAndRender()
 {
     $app = new Application();
     $app->register(new MonologExtension(), array('monolog.class_path' => __DIR__ . '/../../../../vendor/monolog/src'));
     $app['monolog.handler'] = $app->share(function () use($app) {
         return new TestHandler($app['monolog.level']);
     });
     $app->get('/log', function () use($app) {
         $app['monolog']->addDebug('logging a message');
     });
     $app->get('/error', function () {
         throw new \RuntimeException('very bad error');
     });
     $app->error(function (\Exception $e) {
         return 'error handled';
     });
     $this->assertFalse($app['monolog.handler']->hasDebugRecords());
     $this->assertFalse($app['monolog.handler']->hasErrorRecords());
     $request = Request::create('/log');
     $app->handle($request);
     $request = Request::create('/error');
     $app->handle($request);
     $this->assertTrue($app['monolog.handler']->hasDebugRecords());
     $this->assertTrue($app['monolog.handler']->hasErrorRecords());
 }
開發者ID:nooks,項目名稱:Silex,代碼行數:25,代碼來源:MonologExtensionTest.php

示例11: createApplication

 /**
  * Bootstrap Silex Application for tests
  * @method createApplication
  * @return $app              Silex\Application
  */
 public function createApplication()
 {
     $app = new Application(['dev' => true]);
     // errors
     error_reporting(E_ALL ^ E_STRICT);
     $app->error(function (Exception $e, $code) use($app) {
         return $app->json(['error' => $e->getMessage(), 'type' => get_class($e)], $code);
     });
     // database
     $app->register(new DoctrineServiceProvider(), ['db.options' => ['driver' => 'pdo_sqlite', 'path' => __DIR__ . '/tests.db', 'charset' => 'UTF8']]);
     // jwt (json-web-token)
     $app['security.jwt'] = ['secret_key' => 'omg-so-secret-test-!', 'life_time' => 2592000, 'algorithm' => ['HS256'], 'options' => ['header_name' => 'X-Access-Token', 'username_claim' => 'email']];
     $app->register(new SecurityServiceProvider());
     $app->register(new SecurityJWTServiceProvider());
     // mailer
     $app->register(new SwiftmailerServiceProvider(), ['swiftmailer.options' => ['host' => '127.0.0.1', 'port' => '1025']]);
     // twig
     $app->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../templates']);
     $app->register(new UrlGeneratorServiceProvider());
     // simple-user-jwt
     $app['user.jwt.options'] = ['invite' => ['enabled' => true], 'forget' => ['enabled' => true], 'mailer' => ['enabled' => true, 'from' => ['email' => 'do-not-reply@test.com', 'name' => 'Test']]];
     $app->register(new UserProvider());
     // roles
     $app['security.role_hierarchy'] = ['ROLE_INVITED' => ['ROLE_USER'], 'ROLE_REGISTERED' => ['ROLE_INVITED', 'ROLE_ALLOW_INVITE'], 'ROLE_ADMIN' => ['ROLE_REGISTERED']];
     // needed to parse user at each request
     $app['security.firewalls'] = ['login' => ['pattern' => 'register|login|forget|reset', 'anonymous' => true], 'secured' => ['pattern' => '.*$', 'users' => $app->share(function () use($app) {
         return $app['user.manager'];
     }), 'jwt' => ['use_forward' => true, 'require_previous_session' => false, 'stateless' => true]]];
     // controller
     $app->mount('/', new UserProvider());
     return $app;
 }
開發者ID:thcolin,項目名稱:silex-simpleuser-jwt,代碼行數:37,代碼來源:UserControllerTests.php

示例12: register

 public function register(Application $app)
 {
     $app['monolog'] = $app->share(function () use($app) {
         $log = new Logger(isset($app['monolog.name']) ? $app['monolog.name'] : 'myapp');
         $app['monolog.configure']($log);
         return $log;
     });
     $app['monolog.configure'] = $app->protect(function ($log) use($app) {
         $log->pushHandler($app['monolog.handler']);
     });
     $app['monolog.handler'] = function () use($app) {
         return new StreamHandler($app['monolog.logfile'], $app['monolog.level']);
     };
     if (!isset($app['monolog.level'])) {
         $app['monolog.level'] = function () {
             return Logger::DEBUG;
         };
     }
     if (isset($app['monolog.class_path'])) {
         $app['autoloader']->registerNamespace('Monolog', $app['monolog.class_path']);
     }
     $app->before(function (Request $request) use($app) {
         $app['monolog']->addInfo('> ' . $request->getMethod() . ' ' . $request->getRequestUri());
     });
     $app->error(function (\Exception $e) use($app) {
         $app['monolog']->addError($e->getMessage());
     });
     $app->after(function (Request $request, Response $response) use($app) {
         $app['monolog']->addInfo('< ' . $response->getStatusCode());
     });
 }
開發者ID:robo47,項目名稱:Silex,代碼行數:31,代碼來源:MonologServiceProvider.php

示例13: connect

 public function connect(Application $app)
 {
     # bind app to his controller
     $this->app = $app;
     # bind errro handler
     $app->error(array($this, 'handleError'));
 }
開發者ID:icomefromthenet,項目名稱:laterjob,代碼行數:7,代碼來源:BaseProvider.php

示例14: setJsonErrorHandler

 protected function setJsonErrorHandler()
 {
     /** @noinspection PhpUnusedParameterInspection */
     $this->app->error(function (\Exception $e, $code) {
         $message = 'Threw ' . get_class($e) . ': ' . $e->getMessage();
         return new JsonResponse(['error' => $message]);
     });
 }
開發者ID:parsingphase,項目名稱:takeAticket,代碼行數:8,代碼來源:Controller.php

示例15: boot

 public function boot(Application $app)
 {
     $app->error(function (Exception $e) use($app) {
         $app['logger']->addError($e->getMessage());
         $status = $e->getCode() > 99 ? $e->getCode() : 500;
         return new Response($e->getMessage(), $status);
     });
 }
開發者ID:RepoMon,項目名稱:repository,代碼行數:8,代碼來源:ErrorHandler.php


注:本文中的Silex\Application::error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。