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


PHP Application::finish方法代碼示例

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


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

示例1: boot

 public function boot(Application $app)
 {
     $app->finish(function () use($app) {
         // To speed things up (by avoiding Swift Mailer initialization), flush
         // messages only if our mailer has been created (potentially used)
         if ($app['mailer.initialized'] && $app['swiftmailer.use_spool'] && $app['swiftmailer.spooltransport'] instanceof \Swift_Transport_SpoolTransport) {
             $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']);
         }
     });
 }
開發者ID:willianmano,項目名稱:minicurso_phpconference2016,代碼行數:10,代碼來源:SwiftmailerServiceProvider.php

示例2: boot

 public function boot(Application $app)
 {
     // BC: to be removed before 1.0
     if (isset($app['swiftmailer.class_path'])) {
         throw new \RuntimeException('You have provided the swiftmailer.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->finish(function () use($app) {
         $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']);
     });
 }
開發者ID:nlegoff,項目名稱:Silex,代碼行數:10,代碼來源:SwiftmailerServiceProvider.php

示例3: eventHelpersShouldDirectlyAddListenersAfterBoot

 /** @test */
 public function eventHelpersShouldDirectlyAddListenersAfterBoot()
 {
     $app = new Application();
     $fired = false;
     $app->get("/", function () use($app, &$fired) {
         $app->finish(function () use(&$fired) {
             $fired = true;
         });
     });
     $request = Request::create('/');
     $response = $app->handle($request);
     $app->terminate($request, $response);
     $this->assertTrue($fired, 'Event was not fired');
 }
開發者ID:ilosada,項目名稱:chamilo-lms-icpna,代碼行數:15,代碼來源:LazyDispatcherTest.php

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

示例5: testWithAppendMiddlewares

 public function testWithAppendMiddlewares()
 {
     $app = new Application();
     $app->get('/foo', function () {
         return 'bar';
     });
     $finished = false;
     $app->finish(function () use(&$finished) {
         $finished = true;
     });
     $stack = new Builder();
     $stack->push('functional\\Append', '.A')->push('functional\\Append', '.B');
     $app = $stack->resolve($app);
     $request = Request::create('/foo');
     $response = $app->handle($request);
     $app->terminate($request, $response);
     $this->assertSame('bar.B.A', $response->getContent());
     $this->assertTrue($finished);
 }
開發者ID:rodrigopbel,項目名稱:ong,代碼行數:19,代碼來源:SilexApplicationTest.php

示例6: testFinishFilter

 public function testFinishFilter()
 {
     $containerTarget = array();
     $app = new Application();
     $app->finish(function () use(&$containerTarget) {
         $containerTarget[] = '4_filterFinish';
     });
     $app->get('/foo', function () use(&$containerTarget) {
         $containerTarget[] = '1_routeTriggered';
         return new StreamedResponse(function () use(&$containerTarget) {
             $containerTarget[] = '3_responseSent';
         });
     });
     $app->after(function () use(&$containerTarget) {
         $containerTarget[] = '2_filterAfter';
     });
     $app->run(Request::create('/foo'));
     $this->assertSame(array('1_routeTriggered', '2_filterAfter', '3_responseSent', '4_filterFinish'), $containerTarget);
 }
開發者ID:jeanpimentel,項目名稱:slack-invitation,代碼行數:19,代碼來源:ApplicationTest.php

示例7: _iniMiddlewares

 /**
  *  Init middlewares
  * 
  * @param Application $app 
  */
 private function _iniMiddlewares(Application $app)
 {
     // The middleware is run before the routing and the security.
     $app->before(function (Request $request, Application $app) {
         // The request body should only be parsed as JSON
         // if the Content-Type header begins with application/json
         if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
             $content = $request->getContent();
             $data = json_decode($content, true);
             $request->request->replace(is_array($data) ? $data : array());
         }
     }, Application::EARLY_EVENT);
     // The middleware is run after the routing and the security.
     $app->before(function (Request $request, Application $app) {
         // Get route
         $attrs = $request->attributes->all();
         if (isset($attrs['_route'])) {
             $route = $attrs['_route'];
             $app['route'] = $route;
         }
         // Get route params
         if (isset($attrs['_route_params']) && count($attrs['_route_params'])) {
             $route_params = $attrs['_route_params'];
             $app['route_params'] = $route_params;
         }
     });
     // Set event after the Response
     $app->finish(function (Request $request, Response $response) use($app) {
         // Stop event 'eApp'
         $event = $app['watch']->stop('eApp');
         if ($app['debug']) {
             $data = array();
             //----------------
             // Get sum profile params
             $duration = $event->getDuration();
             $memory = $event->getMemory();
             $data['Sum'] = array('t' => $duration, 'm' => $memory);
             // Get periods
             $periods = $event->getPeriods();
             // Get profile params for periods
             if (isset($periods[0])) {
                 $bootstrapDuration = $periods[0]->getDuration();
                 $data['Bootstrap'] = array('t' => $bootstrapDuration);
             }
             if (isset($periods[1])) {
                 $routingDuration = $periods[1]->getDuration();
                 $data['Routing'] = array('t' => $routingDuration);
             }
             if (isset($periods[2])) {
                 $controllerDuration = $periods[2]->getDuration();
                 $data['Controller'] = array('t' => $controllerDuration);
             }
             if (isset($periods[3])) {
                 $renderDuration = $periods[3]->getDuration();
                 $data['Render'] = array('t' => $renderDuration);
             }
             $app['monolog']->addDebug('<== Profile:eApp ==>', $data);
         }
     });
 }
開發者ID:bsa-git,項目名稱:silex-mvc,代碼行數:65,代碼來源:Bootstrap.php

示例8: use

    }
    $studentView = $request->get('isStudentView');
    if (!empty($studentView)) {
        if ($studentView == 'true') {
            $session->set('studentview', 'studentview');
        } else {
            $session->set('studentview', 'teacherview');
        }
    }
});
/** An after application middleware allows you to tweak the Response before it is sent to the client */
$app->after(function (Request $request, Response $response) {
});
/** A "finish" application middleware allows you to execute tasks after the Response has been sent to
 * the client (like sending emails or logging) */
$app->finish(function (Request $request) use($app) {
});
// End Silex Middlewares
// The global variable $charset has been defined in a language file too (trad4all.inc.php), this is legacy situation.
// So, we have to reassign this variable again in order to keep its value right.
$charset = $charset_initial_value;
// The global variable $text_dir has been defined in the language file trad4all.inc.php.
// For determing text direction correspondent to the current language we use now information from the internationalization library.
$text_dir = api_get_text_direction();
/** Setting the is_admin key */
$app['is_admin'] = false;
/** Including routes */
require_once 'routes.php';
// Setting doctrine2 extensions
if (isset($app['configuration']['main_database']) && isset($app['db.event_manager'])) {
    // @todo improvement do not create every time this objects
    $sortableGroup = new Gedmo\Mapping\Annotation\SortableGroup(array());
開發者ID:ilosada,項目名稱:chamilo-lms-icpna,代碼行數:32,代碼來源:global.inc.php

示例9: boot

 public function boot(Application $app)
 {
     $app->mount('/', $this);
     if ($app['debug']) {
         $self = $this;
         $app->after(function () use($app, $self) {
             $self->outOfRequestScopeTypes['request'] = get_class($app['request']);
         });
         $app->finish(function () use($app, $self) {
             if (!$self->processed) {
                 $self->dump($app);
             }
         }, -1);
     }
 }
開發者ID:jlebard,項目名稱:MongoExplorer,代碼行數:15,代碼來源:PimpleDumpProvider.php

示例10: register

 /**
  * @param \Silex\Application $app
  *
  * @return void
  */
 public function register(Application $app)
 {
     $app->finish(function (Request $request) {
         $this->getClient()->persistCacheForRequest($request);
     });
 }
開發者ID:spryker,項目名稱:Storage,代碼行數:11,代碼來源:StorageRequestCacheServiceProvider.php

示例11: boot

 public function boot(Application $app)
 {
     $app->finish(function () use($app) {
         $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']);
     });
 }
開發者ID:nicodmf,項目名稱:Silex,代碼行數:6,代碼來源:SwiftmailerServiceProvider.php

示例12: use

$app->finish(function ($request, $response) use($app) {
    // Définition du point de log
    $ctLog['watchpoint'] = "@" . basename(__FILE__) . ".before." . __LINE__;
    $ctLog['tag'] = "CORTEXT-VESPA";
    // Log de l'user id si l'utilisateur est loggé, sinon on log 0
    $token = $app['security']->getToken();
    if ($token !== null) {
        try {
            if ($token->getUser() === "anon.") {
                $userId = 0;
            } else {
                $userId = $token->getUser()->getId();
            }
        } catch (Exception $e) {
            $userId = 0;
        }
    } else {
        $userId = 0;
    }
    $ctLog['user'] = $userId;
    // Log de l'id de session pour mieux suivre les parcours utilisateurs
    $ctLog['session'] = $app['session']->getId();
    $ctLog['route'] = $request->getPathInfo();
    $ctLog['parameters'] = $request->request->all();
    if (is_null($ctLog['parameters']) || count($ctLog['parameters']) == 0) {
        $ctLog['parameters'] = $request->query->all();
    }
    if (is_null($ctLog['parameters']) || count($ctLog['parameters']) == 0) {
        $ctLog['parameters'] = json_decode($request->getContent(), true);
    }
    if (is_null($ctLog['parameters']) || count($ctLog['parameters']) == 0) {
        $ctLog['parameters'] = $request->attributes->get("_route_params");
    }
    if (!is_null($ctLog['parameters']) && count($ctLog['parameters']) > 0) {
        array_walk($ctLog['parameters'], function (&$v, $k) {
            if (in_array($k, array("_password", "password", "confirm-password"), TRUE)) {
                $v = "";
            }
        });
    }
    $ctLog['type'] = $request->getMethod();
    $ctLog['status'] = $response->getStatusCode();
    $ctLog['response'] = json_decode($response->getContent());
    if (!$ctLog['response']) {
        $ctLog['response'] = "Not JSON";
    }
    $duration = $app['stopwatch']->stop('vespa');
    $ctLog['duration'] = $duration->getDuration();
    $ctLog['ip'] = $request->getClientIp();
    $ctLog['msg'] = "";
    // Output de la ligne de log
    $app['monolog']->addInfo("[VESPA] " . json_encode($ctLog, JSON_UNESCAPED_SLASHES));
    // Output vers mysql
    array_walk($ctLog, function (&$v, $k) {
        // Les objects provoquent une erreur et les array apparaissent comme "array" en bdd, alors on encode tout ça pour les avoir en base
        if (in_array(gettype($v), array("object", "array"), TRUE)) {
            $v = json_encode($v, JSON_UNESCAPED_SLASHES);
        }
    });
    $app['mysqlog']->addInfo("[VESPA]", $ctLog);
});
開發者ID:ut7,項目名稱:PestObserver,代碼行數:61,代碼來源:index.php


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