當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。