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


PHP HttpKernel::terminate方法代碼示例

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


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

示例1: run

 public function run()
 {
     $this->response = $this->kernel->handle($this->request);
     $this->response->send();
     $this->kernel->terminate($this->request, $this->response);
     return $this;
 }
開發者ID:Asmerok,項目名稱:UCCA,代碼行數:7,代碼來源:Application.php

示例2: run

 /**
  * run Application
  */
 public function run()
 {
     $response = $this->container->get(TwigResponse::class);
     $response->setTemplate('error/404');
     try {
         $this->eventDispatcher->addSubscriber($this->routerListener);
         $response = $this->httpKernel->handle($this->request);
     } catch (ResourceNotFoundException $e) {
         $response->setContent(['message' => $e->getMessage()]);
     } catch (\Exception $e) {
         //            $response->setContent(['message' => $e->getMessage()]);
         throw $e;
     } finally {
         $response->send();
         $this->httpKernel->terminate($this->request, $response);
     }
 }
開發者ID:akentner,項目名稱:incoming-ftp,代碼行數:20,代碼來源:App.php

示例3: sendResponse

 /**
  * Triggers kernel.response and sends a form response.
  *
  * @param \Symfony\Component\HttpFoundation\Response $response
  *   A response object.
  */
 protected function sendResponse(Response $response)
 {
     $request = $this->requestStack->getCurrentRequest();
     $event = new FilterResponseEvent($this->httpKernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
     $this->eventDispatcher->dispatch(KernelEvents::RESPONSE, $event);
     // Prepare and send the response.
     $event->getResponse()->prepare($request)->send();
     $this->httpKernel->terminate($request, $response);
 }
開發者ID:alnutile,項目名稱:drunatra,代碼行數:15,代碼來源:FormBuilder.php

示例4: __invoke

 /**
  * {@inheritdoc}
  */
 public function __invoke(Request $request)
 {
     $context = new RequestContext();
     $context->fromRequest($request);
     $this->eventDispatcher->addSubscriber(new RouterListener(new UrlMatcher($this->routeCollection, $context)));
     $kernel = new HttpKernel($this->eventDispatcher, new ControllerResolverActionResolverAdapter($this->actionResolver));
     $response = $kernel->handle($request);
     $response->send();
     $kernel->terminate($request, $response);
 }
開發者ID:cotapreco,項目名稱:kernel,代碼行數:13,代碼來源:Application.php

示例5: __construct

 public function __construct()
 {
     $container = new ContainerBuilder();
     $loader = new YamlFileLoader($container, new FileLocator(ROOT_PATH . '/app/config'));
     $loader->load('services.yml');
     $loader = new YamlFileLoader($container, new FileLocator(ROOT_PATH . '/src/config'));
     $loader->load('services.yml');
     $container->compile();
     $routes = $container->get('router')->getRoutes();
     $request = Request::createFromGlobals();
     $matcher = new UrlMatcher($routes, new RequestContext());
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new AuthenticationListener($container));
     $dispatcher->addSubscriber(new FirewallListener($container, $matcher));
     $dispatcher->addSubscriber(new RouterListener($matcher));
     $resolver = new MyControllerResolver($container);
     $kernel = new HttpKernel($dispatcher, $resolver);
     $response = $kernel->handle($request);
     $response->send();
     $kernel->terminate($request, $response);
     if (DEV_MODE) {
         $container->get('profiler')->showProfiler();
     }
 }
開發者ID:joussin,項目名稱:framework,代碼行數:24,代碼來源:FrontalController.php

示例6: testTerminate

 public function testTerminate()
 {
     $dispatcher = new EventDispatcher();
     $kernel = new HttpKernel($dispatcher, $this->getResolver());
     $dispatcher->addListener(KernelEvents::TERMINATE, function ($event) use(&$called, &$capturedKernel, &$capturedRequest, &$capturedResponse) {
         $called = true;
         $capturedKernel = $event->getKernel();
         $capturedRequest = $event->getRequest();
         $capturedResponse = $event->getResponse();
     });
     $kernel->terminate($request = Request::create('/'), $response = new Response());
     $this->assertTrue($called);
     $this->assertEquals($kernel, $capturedKernel);
     $this->assertEquals($request, $capturedRequest);
     $this->assertEquals($response, $capturedResponse);
 }
開發者ID:omusico,項目名稱:lafayettehelps.com,代碼行數:16,代碼來源:HttpKernelTest.php

示例7: RouteCollection

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
$routes = new RouteCollection();
$routes->add('hello', new Route('/add/{param1}', array('_controller' => function (Request $request) {
    return new Response("asdfasdf" . $request->get("param1"));
})));
$routes->add('hello', new Route('/', array('_controller' => function (Request $request) {
    return new Response("Asdf");
})));
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
ErrorHandler::register();
ExceptionHandler::register();
$request = Request::createFromGlobals();
$matcher = new UrlMatcher($routes, new RequestContext());
$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber(new RouterListener($matcher));
$resolver = new ControllerResolver();
$kernel = new HttpKernel($dispatcher, $resolver);
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
開發者ID:itav,項目名稱:httpkernel,代碼行數:30,代碼來源:index.php

示例8: run

 public function run($group = null, $controller = null, $function = null)
 {
     // 注冊框架運行的服務.
     $this->handle();
     // 請求參數
     $request = Request::capture();
     // 設置請求
     $this->app['request'] = $request;
     // 入口文件
     $baseUrl = $request->getBaseUrl();
     $this->filename = empty($baseUrl) ? $request->getSchemeAndHttpHost() . $request->server('SCRIPT_FILENAME') : $request->getSchemeAndHttpHost() . $baseUrl;
     if ($path_info = trim($request->getPathInfo(), '/')) {
         $args = explode('/', $path_info);
         define('BY_PATH_INFO', true);
         if (count($args) == 1) {
             $controller = $controller ?: $args[0];
         } elseif (count($args) >= 2) {
             $controller = $controller ?: $args[0];
             $function = $function ?: $args[1];
         }
     }
     // ======== 開始調度,設置調度那個控製器===============
     $group = ucfirst($group) ?: 'Web';
     $controller = $controller ?: $request->get('c', 'DefaultController');
     $controller = strrpos($controller, 'Controller') !== false ? $controller : $controller . 'Controller';
     $function = $function ?: $request->get('m', 'index');
     $class = '\\App\\Controllers\\' . $group . '\\' . ucfirst($controller);
     $load_class = $class . "::" . $function;
     // ======== 基礎控製器設置結束 ========================
     // 檢查控製器類存在不
     if (!class_exists($class)) {
         $class = '\\App\\Controllers\\' . $group . '\\NoFoundController';
         $function = 'index';
         $load_class = $class . '::' . $function;
     }
     // 如果沒有找到類方法,設置為404
     if (!is_callable([$class, $function])) {
         $class = NoFoundController::class;
         $function = 'index';
         $load_class = NoFoundController::class . '::' . $function;
     }
     // 事件調度器
     $dispatcher = new EventDispatcher();
     // 調度控製器參數事件
     $dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function ($event) {
         // 獲取調度的參數
         $arguments = $event->getArguments();
         // 獲取調度的控製器
         $controller = $event->getController();
         // 獲取類
         $class = $controller[0];
         // 獲取方法
         $function = $controller[1];
         // 檢查調度方法在不在,在的話轉發到調度方法去
         if (method_exists($class, '_do_action')) {
             $controller = [$class, '_do_action'];
             // 將方法設置為第一個參數
             array_unshift($arguments, $function);
             // 重新調度
             $event->setController($controller);
             $event->setArguments($arguments);
         }
     });
     // 設置視圖事件回調
     $dispatcher->addListener(KernelEvents::VIEW, function ($event) {
         $result = $event->getControllerResult();
         // 重置視圖的錯誤報告,忽略掉NOTICE的,視圖太多NOTIC了
         $error_report = error_reporting();
         error_reporting(E_ALL ^ E_NOTICE);
         $event->setResponse(new Response($result instanceof View ? $result->render() : $result));
         // 恢複原來的錯誤報告
         error_reporting($error_report);
     });
     // 設置異常回調
     $dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) {
         // 獲取異常
         $e = $event->getException();
         // 如果是自定義異常
         if ($e instanceof HttpResponseException) {
             // 設置成正常響應
             $event->setResponse($e->getResponse());
         }
     });
     // 以下是Symfony默認HTTP調度,無需修改
     $controllerResolver = new ControllerResolver();
     $argumentResolver = new ArgumentResolver();
     $kernel = new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);
     $request->attributes->set('_controller', $load_class);
     $response = $kernel->handle($request);
     $response->send();
     $kernel->terminate($request, $response);
 }
開發者ID:skyguest,項目名稱:ecadapter,代碼行數:92,代碼來源:Core.php

示例9: handle

 public function handle()
 {
     $resolver = new Resolver();
     $kernel = new HttpKernel($this->getDispatcher(), $resolver);
     $response = $kernel->handle($this->getRequest());
     $response->send();
     $kernel->terminate($this->getRequest(), $response);
 }
開發者ID:primephp,項目名稱:framework,代碼行數:8,代碼來源:Kernel.php


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