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