当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpKernel::handle方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\HttpKernel::handle方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpKernel::handle方法的具体用法?PHP HttpKernel::handle怎么用?PHP HttpKernel::handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpKernel\HttpKernel的用法示例。


在下文中一共展示了HttpKernel::handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getRoute

 /**
  * @param null|string $Path
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  */
 public function getRoute($Path = null)
 {
     try {
         return $this->SymfonyHttpKernel->handle(Request::createFromGlobals())->getContent();
     } catch (\Exception $E) {
         throw new ComponentException($E->getMessage(), $E->getCode(), $E);
     }
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:14,代码来源:SymfonyRouter.php

示例3: getPreprocessorWriterResponse

 public function getPreprocessorWriterResponse($preprocessorRouteName, array $attributes, Request $currentRequest)
 {
     // For localhost, the way is the same as for public to private forward.
     $attributes['_controller'] = $this->router->getRouteCollection()->get($preprocessorRouteName)->getDefault('_controller');
     $subRequest = $currentRequest->duplicate(null, null, $attributes);
     $response = $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     /* @var $response \Symfony\Component\HttpFoundation\Response */
     $response->setStatusCode($response->getStatusCode(), $response->headers->get('ps_status_text', null));
     return $response;
 }
开发者ID:xGouley,项目名称:PSPublicWriterBundle,代码行数:10,代码来源:LocalhostForwarder.php

示例4: handle

 /**
  * Handles a Request to convert it to a Response.
  *
  * When $catch is true, the implementation must catch all exceptions
  * and do its best to convert them to a Response instance.
  *
  * @param Request $request A Request instance
  * @param integer $type    The type of the request
  *                         (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
  * @param Boolean $catch   Whether to catch exceptions or not
  *
  * @return Response A Response instance
  *
  * @throws \Exception When an Exception occurs during processing
  *
  * @api
  *
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     // for backward compatibility
     $this->container->set('request', $request);
     $this->container->get('request.context')->fromRequest($request);
     $response = parent::handle($request, $type, $catch);
     return $response;
 }
开发者ID:vigourouxjulien,项目名称:thelia,代码行数:26,代码来源:TheliaHttpKernel.php

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

示例6: testHandleSetsTheRequest

 public function testHandleSetsTheRequest()
 {
     $request = Request::create('/');
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->exactly(2))->method('set')->with('request', $request);
     $kernel = new HttpKernel($container, new EventDispatcher(), $this->getResolver());
     $kernel->handle($request);
 }
开发者ID:rsky,项目名称:symfony,代码行数:8,代码来源:HttpKernelTest.php

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

示例8: handle

 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $this->container->enterScope('request');
     $this->container->set('request', $request, 'request');
     try {
         $response = parent::handle($request, $type, $catch);
     } catch (\Exception $e) {
         $this->container->leaveScope('request');
         throw $e;
     }
     $this->container->leaveScope('request');
     return $response;
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:13,代码来源:HttpKernel.php

示例9: testUrl

 public function testUrl()
 {
     $routes = new RouteCollection();
     $routes->add('hello', new Route('/hello', array('_controller' => function (Request $request) {
         return new Response("Hello");
     })));
     $matcher = new UrlMatcher($routes, new RequestContext());
     // create the Request object
     $dispatcher = new EventDispatcher();
     $dispatcher->addSubscriber(new RouterListener($matcher));
     $resolver = new ControllerResolver();
     $kernel = new HttpKernel($dispatcher, $resolver);
     $request = Request::create('/hello');
     $response = $kernel->handle($request);
     echo $response->getContent();
     //
     // actually execute the kernel, which turns the request into a response
     // // by dispatching events, calliwaang a controller, and returning the response
     // $response = $kernel->handle($request);
 }
开发者ID:sysfony,项目名称:chess,代码行数:20,代码来源:ChessTest.php

示例10: it_converts_exception_to_json

 /** @test */
 public function it_converts_exception_to_json()
 {
     $resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
     $resolver->expects($this->once())->method('getController')->will($this->returnValue(function () {
         throw new NotFoundHttpException();
     }));
     $resolver->expects($this->once())->method('getArguments')->will($this->returnValue([]));
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $logger->expects($this->once())->method('error');
     $dispatcher = new EventDispatcher();
     $httpKernel = new HttpKernel($dispatcher, $resolver);
     $dispatcher->addSubscriber(new RequestFormatNegotiationListener());
     $dispatcher->addSubscriber(new RequestFormatValidationListener());
     $dispatcher->addSubscriber(new ResponseConversionListener());
     $dispatcher->addSubscriber(new ExceptionConversionListener($logger));
     $request = Request::create('/exception', 'GET', [], [], [], ['HTTP_ACCEPT' => 'application/json']);
     $request->attributes->set('_format', 'json');
     $response = $httpKernel->handle($request)->prepare($request);
     $this->assertSame(404, $response->getStatusCode());
     $this->assertSame('application/vnd.error+json', $response->headers->get('Content-Type'));
     $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'Not Found']), $response->getContent());
 }
开发者ID:jsor,项目名称:stack-hal,代码行数:23,代码来源:HttpKernelTest.php

示例11: __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

示例12: testVerifyRequestStackPushPopDuringHandle

 public function testVerifyRequestStackPushPopDuringHandle()
 {
     $request = new Request();
     $stack = $this->getMock('Symfony\\Component\\HttpFoundation\\RequestStack', array('push', 'pop'));
     $stack->expects($this->at(0))->method('push')->with($this->equalTo($request));
     $stack->expects($this->at(1))->method('pop');
     $dispatcher = new EventDispatcher();
     $kernel = new HttpKernel($dispatcher, $this->getResolver(), $stack);
     $kernel->handle($request, HttpKernelInterface::MASTER_REQUEST);
 }
开发者ID:GeorgeShazkho,项目名称:micros-de-conce,代码行数:10,代码来源:HttpKernelTest.php

示例13: handle

 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
 {
     $this->catch = $catch;
     $this->backendRequest = $request;
     return parent::handle($request, $type, $catch);
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:6,代码来源:TestHttpKernel.php

示例14: RouteCollection

require_once __DIR__ . '/../vendor/autoload.php';
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,代码行数:31,代码来源:index.php

示例15: testInconsistentClientIpsOnMasterRequests

 /**
  * @expectedException Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  */
 public function testInconsistentClientIpsOnMasterRequests()
 {
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener(KernelEvents::REQUEST, function ($event) {
         $event->getRequest()->getClientIp();
     });
     $kernel = new HttpKernel($dispatcher, $this->getResolver());
     $request = new Request();
     $request->setTrustedProxies(array('1.1.1.1'));
     $request->server->set('REMOTE_ADDR', '1.1.1.1');
     $request->headers->set('FORWARDED', '2.2.2.2');
     $request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
     $kernel->handle($request, $kernel::MASTER_REQUEST, false);
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:17,代码来源:HttpKernelTest.php


注:本文中的Symfony\Component\HttpKernel\HttpKernel::handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。