当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::after方法代码示例

本文整理汇总了PHP中Silex\Application::after方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::after方法的具体用法?PHP Application::after怎么用?PHP Application::after使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Silex\Application的用法示例。


在下文中一共展示了Application::after方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 /**
  * {@inheritDoc}
  */
 public function register(SilexApplication $app)
 {
     $app['payum.api.controller.root'] = $app->share(function () {
         return new RootController();
     });
     $app['payum.api.controller.payment'] = $app->share(function () use($app) {
         return new PaymentController($app['payum.security.token_factory'], $app['payum.security.http_request_verifier'], $app['payum'], $app['api.view.order_to_json_converter'], $app['form.factory'], $app['api.view.form_to_json_converter']);
     });
     $app['payum.api.controller.gateway'] = $app->share(function () use($app) {
         return new GatewayController($app['form.factory'], $app['url_generator'], $app['api.view.form_to_json_converter'], $app['payum.gateway_config_storage'], $app['api.view.gateway_config_to_json_converter']);
     });
     $app['payum.api.controller.gateway_meta'] = $app->share(function () use($app) {
         return new GatewayMetaController($app['form.factory'], $app['api.view.form_to_json_converter'], $app['payum']);
     });
     $app->get('/', 'payum.api.controller.root:rootAction')->bind('api_root');
     $app->get('/payments/meta', 'payum.api.controller.payment:metaAction')->bind('payment_meta');
     $app->get('/payments/{payum_token}', 'payum.api.controller.payment:getAction')->bind('payment_get');
     $app->put('/payments/{payum_token}', 'payum.api.controller.payment:updateAction')->bind('payment_update');
     $app->delete('/payments/{payum_token}', 'payum.api.controller.payment:deleteAction')->bind('payment_delete');
     $app->post('/payments', 'payum.api.controller.payment:createAction')->bind('payment_create');
     $app->get('/payments', 'payum.api.controller.payment:allAction')->bind('payment_all');
     $app->get('/gateways/meta', 'payum.api.controller.gateway_meta:getAllAction')->bind('payment_factory_get_all');
     $app->get('/gateways', 'payum.api.controller.gateway:allAction')->bind('gateway_all');
     $app->get('/gateways/{name}', 'payum.api.controller.gateway:getAction')->bind('gateway_get');
     $app->delete('/gateways/{name}', 'payum.api.controller.gateway:deleteAction')->bind('gateway_delete');
     $app->post('/gateways', 'payum.api.controller.gateway:createAction')->bind('gateway_create');
     $app->before(function (Request $request, Application $app) {
         if (in_array($request->getMethod(), array('GET', 'OPTIONS', 'DELETE'))) {
             return;
         }
         if ('json' !== $request->getContentType()) {
             throw new BadRequestHttpException('The request content type is invalid. It must be application/json');
         }
         $decodedContent = json_decode($request->getContent(), true);
         if (null === $decodedContent) {
             throw new BadRequestHttpException('The request content is not valid json.');
         }
         $request->attributes->set('content', $decodedContent);
     });
     $app->after(function (Request $request, Response $response) use($app) {
         if ($response instanceof JsonResponse && $app['debug']) {
             $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
         }
     });
     $app->after($app["cors"]);
     $app->error(function (\Exception $e, $code) use($app) {
         if ('json' !== $app['request']->getContentType()) {
             return;
         }
         return new JsonResponse(array('exception' => get_class($e), 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'stackTrace' => $e->getTraceAsString()));
     }, $priority = -100);
 }
开发者ID:Headd2k,项目名称:PayumServer,代码行数:55,代码来源:ApiControllerProvider.php

示例2: register

 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     // handling CORS preflight request
     $app->before(function (Request $request) {
         if ($request->getMethod() === 'OPTIONS') {
             $response = new Response();
             $response->headers->set('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
             $response->headers->set('Access-Control-Allow-Headers', 'Content-Type');
             $response->headers->set('Access-Control-Allow-Origin', '*');
             $response->setStatusCode(200);
             return $response;
         }
     }, $app::EARLY_EVENT);
     $app->before(function (Request $request) {
         if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
             $data = json_decode($request->getContent(), true);
             $request->request->replace(is_array($data) ? $data : []);
         }
     });
     // CORS domain
     $app->after(function (Request $request, Response $response) {
         $response->headers->set('Access-Control-Allow-Origin', '*');
         return $response;
     });
     // Returns the status code in the response body
     $app->after(function (Request $request, Response $response) {
         $status = $response->getStatusCode();
         // Errors
         if ($status >= 400 && $response instanceof JsonResponse) {
             $data = json_decode($response->getContent(), true);
             if (!is_array($data)) {
                 $data = [];
             }
             $response->setData(array_merge($data, ['status' => $status]));
         }
         return $response;
     });
     // Converts HTTP exception to response
     $app->error(function (\Exception $e) {
         $response = null;
         switch (true) {
             case $e instanceof NotFoundHttpException:
             case $e instanceof BadRequestHttpException:
                 $response = new JsonResponse(['message' => $e->getMessage()], $e->getStatusCode(), $e->getHeaders());
                 break;
             default:
         }
         return $response;
     });
 }
开发者ID:qferr,项目名称:silex-rest-provider-service,代码行数:53,代码来源:RestServiceProvider.php

示例3: boot

 public function boot(Application $app)
 {
     $app->before(function () use($app) {
         $app['np.extensions']['debug'] = $app['debug'];
         $app['np.extensions']['admin'] = $app['np.admin'];
         $app['np.extensions']->boot();
         // add template paths for all extensions and blocks
         $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function ($loader, $app) {
             foreach ($app['np.extensions']->getAll() as $namespace => $extension) {
                 $loader->addPath($extension->getPath(), $namespace);
             }
             foreach ($app['np.extensions']['block_types'] as $blockType) {
                 $loader->addPath($blockType->getPath(), 'block_' . $app['np.slug_helper']->slugify($blockType->name));
             }
             return $loader;
         }));
         // load collected twig functions
         $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
             foreach ($app['np.extensions']['twig_extensions'] as $extension) {
                 $twig->addExtension($extension);
             }
             return $twig;
         }));
     });
     $app->after(function (Request $request, Response $response) use($app) {
         if ($response instanceof BinaryFileResponse || !$app['np.extensions']->booted) {
             return;
         }
         $app['np.extensions']->prepareSnippets();
         $response->setContent($app['np.extensions']['snippet_queue']->processAll($app, $response->getContent()));
     });
 }
开发者ID:nodepub,项目名称:core,代码行数:32,代码来源:ExtensionServiceProvider.php

示例4: boot

 /**
  * @param Application $app
  */
 public function boot(Application $app)
 {
     $options = $this->options;
     $cors = new CorsService($options);
     // handle OPTIONS preflight request if necessary
     $app->before(function (Request $request) use($app, $cors, $options) {
         if (!$cors->isCorsRequest($request)) {
             return;
         }
         if ($cors->isPreflightRequest($request)) {
             $response = $cors->handlePreflightRequest($request);
             $denied_codes = array(Response::HTTP_METHOD_NOT_ALLOWED, Response::HTTP_FORBIDDEN);
             $is_denied = in_array($response->getStatusCode(), $denied_codes);
             if ($is_denied && !empty($options['denied_reponse_class'])) {
                 $response = new $options['denied_reponse_class']($response->getContent(), $response->getStatusCode(), $response->headers->all());
             }
             return $response;
         }
         if (!$cors->isActualRequestAllowed($request)) {
             if (!empty($options['denied_reponse_class'])) {
                 $response = new $options['denied_reponse_class']('Not allowed', 403);
             } else {
                 $response = new Response('Not allowed.', 403);
             }
             return $response;
         }
     }, Application::EARLY_EVENT);
     // when the response is sent back, add CORS headers if necessary
     $app->after(function (Request $request, Response $response) use($cors) {
         if (!$cors->isCorsRequest($request)) {
             return;
         }
         $cors->addActualRequestHeaders($response, $request);
     });
 }
开发者ID:andreiashu,项目名称:silex-stackcors-provider,代码行数:38,代码来源:CorsServiceProvider.php

示例5: 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

示例6: 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

示例7: boot

 public function boot(Application $app)
 {
     $app->before(function (Request $request, Application $app) {
         //echo "Before Service Event<hr>";
     });
     $app->after(function (Request $request, Response $response) {
         //echo "After Service Event <hr>";
     });
 }
开发者ID:streetcolor,项目名称:silex-mvc,代码行数:9,代码来源:EventServiceProvider.php

示例8: boot

 public function boot(Application $app)
 {
     $app->before($app['monolog.boot.before']);
     /*
      * 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($app['monolog.boot.error'], -4);
     $app->after($app['monolog.boot.after']);
 }
开发者ID:romainneutron,项目名称:Silex,代码行数:10,代码来源:MonologServiceProvider.php

示例9: boot

 public function boot(Application $app)
 {
     if ($app['lazycache']->isActive()) {
         $app->before(function (Request $request) use($app) {
             return $app['lazycache']->before($request);
         });
         $app->after(function (Request $request, Response $response) use($app) {
             return $app['lazycache']->after($request, $response);
         });
     }
 }
开发者ID:konstantin-s,项目名称:silex-lazycache,代码行数:11,代码来源:LazyCacheProvider.php

示例10: boot

 public function boot(Application $app)
 {
     $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());
     }, 255);
     $app->after(function (Request $request, Response $response) use($app) {
         $app['monolog']->addInfo('< ' . $response->getStatusCode());
     });
 }
开发者ID:nicodmf,项目名称:Silex,代码行数:12,代码来源:MonologServiceProvider.php

示例11: register

 public function register(Application $app)
 {
     $app->after(function (Request $request, Response $response) use($app) {
         $response->headers->set('Access-Control-Allow-Origin', $request->headers->get('origin', '*'));
         $response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
         $response->headers->set('Access-Control-Allow-Credentials', 'Bearer');
         $response->headers->set('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
     });
     $app->before(function (Request $request) use($app) {
         if ($request->getMethod() === 'OPTIONS') {
             return new Response('', 200);
         }
     });
 }
开发者ID:myurasov,项目名称:rest-api-tools,代码行数:14,代码来源:CORSProvider.php

示例12: boot

 public function boot(Application $app)
 {
     // BC: to be removed before 1.0
     if (isset($app['monolog.class_path'])) {
         throw new \RuntimeException('You have provided the monolog.class_path parameter. The autoloader has been removed from Silex. It is recommended that you use Composer to manage your dependencies and handle your autoloading. If you are already using Composer, you can remove the parameter. See http://getcomposer.org for more information.');
     }
     $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());
     }, 255);
     $app->after(function (Request $request, Response $response) use($app) {
         $app['monolog']->addInfo('< ' . $response->getStatusCode());
     });
 }
开发者ID:assistechnologie,项目名称:webui,代码行数:16,代码来源:MonologServiceProvider.php

示例13: boot

 public function boot(Application $app)
 {
     $app->before(function (Request $request) use($app) {
         $app['monolog']->addInfo('> ' . $request->getMethod() . ' ' . $request->getRequestUri());
     });
     $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);
         } else {
             $app['monolog']->addCritical($message);
         }
     }, 255);
     $app->after(function (Request $request, Response $response) use($app) {
         $app['monolog']->addInfo('< ' . $response->getStatusCode());
     });
 }
开发者ID:KingNoosh,项目名称:Teknik,代码行数:17,代码来源:MonologServiceProvider.php

示例14: testCallbacksAsServices

 public function testCallbacksAsServices()
 {
     $app = new Application();
     $app['service'] = $app->share(function () {
         return new self();
     });
     $app->before('service:beforeApp');
     $app->after('service:afterApp');
     $app->finish('service:finishApp');
     $app->error('service:error');
     $app->on('kernel.request', 'service:onRequest');
     $app->match('/', 'service:controller')->convert('foo', 'service:convert')->before('service:before')->after('service:after');
     $request = Request::create('/');
     $response = $app->handle($request);
     $app->terminate($request, $response);
     $this->assertEquals(array('CONVERT', 'BEFORE APP', 'ON REQUEST', 'BEFORE', 'ERROR', 'AFTER', 'AFTER APP', 'FINISH APP'), $app['service']->called);
 }
开发者ID:syntropysoftware,项目名称:cryptoffice-frontend,代码行数:17,代码来源:CallbackServicesTests.php

示例15: setupAfterMiddleware

 protected function setupAfterMiddleware(Application $app)
 {
     $app->after(function (Request $request, Response $response) use($app) {
         switch ($app['newrelic.options']['transaction_name_method']) {
             case 'route':
                 $name = $request->attributes->get('_route');
                 break;
             case 'uri':
             default:
                 $name = $request->getRequestUri();
                 break;
         }
         if (!$name) {
             $name = NewRelicServiceProvider::DEFAULT_TRANSACTION_NAME;
         }
         $app['newrelic']->nameTransaction($name);
     });
 }
开发者ID:mcuadros,项目名称:silex-newrelic,代码行数:18,代码来源:NewRelicServiceProvider.php


注:本文中的Silex\Application::after方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。