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


PHP Application::before方法代碼示例

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


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

示例1: use

     return $monolog;
 }));
 // handle API content negotiation
 $app->before(function (Request $request) use($app) {
     // register custom API format
     $request->setFormat(Result::FORMAT_JSON_EXTENDED, V1::$extendedContentTypes['json']);
     $request->setFormat(Result::FORMAT_YAML_EXTENDED, V1::$extendedContentTypes['yaml']);
     $request->setFormat(Result::FORMAT_JSONP_EXTENDED, V1::$extendedContentTypes['jsonp']);
     $request->setFormat(Result::FORMAT_JSONP, array('text/javascript', 'application/javascript'));
     // handle content negociation
     $priorities = array('application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript');
     foreach (V1::$extendedContentTypes['json'] as $priorities[]) {
     }
     foreach (V1::$extendedContentTypes['yaml'] as $priorities[]) {
     }
     $format = $app['format.negociator']->getBest($request->headers->get('accept'), $priorities);
     // throw unacceptable http error if API can not handle asked format
     if (null === $format) {
         $app->abort(406);
     }
     // set request format according to negotiated content or override format with JSONP if callback parameter is defined
     if (trim($request->get('callback')) !== '') {
         $request->setRequestFormat(Result::FORMAT_JSONP);
     } else {
         $request->setRequestFormat($request->getFormat($format->getValue()));
     }
     // tells whether asked format is extended or not
     $request->attributes->set('_extended', in_array($request->getRequestFormat(Result::FORMAT_JSON), array(Result::FORMAT_JSON_EXTENDED, Result::FORMAT_YAML_EXTENDED, Result::FORMAT_JSONP_EXTENDED)));
 }, PhraseaApplication::EARLY_EVENT);
 $app->after(function (Request $request, Response $response) use($app) {
     if ($request->getRequestFormat(Result::FORMAT_JSON) === Result::FORMAT_JSONP && !$response->isOk() && !$response->isServerError()) {
         $response->setStatusCode(200);
開發者ID:nlegoff,項目名稱:Phraseanet,代碼行數:32,代碼來源:Api.php

示例2: PhraseaExceptionHandlerSubscriber

 $app['exception_handler'] = $app->share(function ($app) {
     return new PhraseaExceptionHandlerSubscriber($app['phraseanet.exception_handler']);
 });
 $app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
     $monolog->pushProcessor(new WebProcessor());
     return $monolog;
 }));
 $app->before(function (Request $request) use($app) {
     if (0 === strpos($request->getPathInfo(), '/setup')) {
         if (!$app['phraseanet.configuration-tester']->isInstalled()) {
             if (!$app['phraseanet.configuration-tester']->isBlank()) {
                 if ('setup_upgrade_instructions' !== $app['request']->attributes->get('_route')) {
                     return $app->redirectPath('setup_upgrade_instructions');
                 }
             }
         } elseif (!$app['phraseanet.configuration-tester']->isBlank()) {
             return $app->redirectPath('homepage');
         }
     } else {
         if (false === strpos($request->getPathInfo(), '/include/minify')) {
             $app['firewall']->requireSetup();
         }
     }
 }, Application::EARLY_EVENT);
 $app->bindRoutes();
 if (PhraseaApplication::ENV_DEV === $app->getEnvironment()) {
     $app->register($p = new WebProfilerServiceProvider(), ['profiler.cache_dir' => $app['cache.path'] . '/profiler']);
     $app->mount('/_profiler', $p);
     if ($app['phraseanet.configuration-tester']->isInstalled()) {
         $app->register(new DoctrineProfilerServiceProvider());
         $app['db'] = $app->share(function (PhraseaApplication $app) {
開發者ID:luisbrito,項目名稱:Phraseanet,代碼行數:31,代碼來源:Root.php

示例3: ApiExceptionHandlerSubscriber

 $app['exception_handler'] = $app->share(function ($app) {
     $handler = new ApiExceptionHandlerSubscriber($app);
     $handler->setLogger($app['monolog']);
     return $handler;
 });
 $app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
     $monolog->pushProcessor(new WebProcessor());
     return $monolog;
 }));
 $app['phraseanet.content-negotiation.priorities'] = array_merge(V1::$extendedContentTypes['json'], V1::$extendedContentTypes['jsonp'], V1::$extendedContentTypes['yaml'], ['application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript']);
 $app['phraseanet.content-negotiation.custom_formats'] = [Result::FORMAT_JSON_EXTENDED => V1::$extendedContentTypes['json'], Result::FORMAT_YAML_EXTENDED => V1::$extendedContentTypes['yaml'], Result::FORMAT_JSONP_EXTENDED => V1::$extendedContentTypes['jsonp'], Result::FORMAT_JSONP => ['text/javascript', 'application/javascript']];
 // handle API content negotiation
 $app->before(function (Request $request) {
     // set request format according to negotiated content or override format with JSONP if callback parameter is defined
     if (trim($request->get('callback')) !== '') {
         $request->setRequestFormat(Result::FORMAT_JSONP);
     }
     // tells whether asked format is extended or not
     $request->attributes->set('_extended', in_array($request->getRequestFormat(Result::FORMAT_JSON), array(Result::FORMAT_JSON_EXTENDED, Result::FORMAT_YAML_EXTENDED, Result::FORMAT_JSONP_EXTENDED)));
 }, PhraseaApplication::EARLY_EVENT);
 $app->after(function (Request $request, Response $response) {
     if ($request->getRequestFormat(Result::FORMAT_JSON) === Result::FORMAT_JSONP && !$response->isOk() && !$response->isServerError()) {
         $response->setStatusCode(200);
     }
     // set response content type
     if (!$response->headers->get('Content-Type')) {
         $response->headers->set('Content-Type', $request->getMimeType($request->getRequestFormat(Result::FORMAT_JSON)));
     }
 });
 $app->register(new JsonSchemaServiceProvider());
 $app->get('/api/', function (Request $request, SilexApplication $app) {
     return Result::create($request, ['name' => $app['conf']->get(['registry', 'general', 'title']), 'type' => 'phraseanet', 'description' => $app['conf']->get(['registry', 'general', 'description']), 'documentation' => 'https://docs.phraseanet.com/Devel', 'versions' => ['1' => ['number' => V1::VERSION, 'uri' => '/api/v1/', 'authenticationProtocol' => 'OAuth2', 'authenticationVersion' => 'draft#v9', 'authenticationEndPoints' => ['authorization_token' => '/api/oauthv2/authorize', 'access_token' => '/api/oauthv2/token']]]])->createResponse();
開發者ID:luisbrito,項目名稱:Phraseanet,代碼行數:32,代碼來源:Api.php


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