当前位置: 首页>>代码示例>>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;未经允许,请勿转载。