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


PHP HttpKernel\HttpKernel类代码示例

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


在下文中一共展示了HttpKernel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

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

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

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

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

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

示例8: __construct

 public function __construct()
 {
     $this->shared = array();
     $this->providers = array();
     $resolver = new ControllerResolver($this);
     $env = $this->getEnvironment();
     $this->dispatcher = new EventDispatcher();
     $this->dispatcher->addSubscriber(new EventListener\RedirectListener());
     $this->dispatcher->addSubscriber(new HttpKernel\EventListener\ResponseListener('UTF-8'));
     $this->dispatcher->addSubscriber(new ExceptionHandler($env == 'dev'));
     parent::__construct($this->dispatcher, $resolver);
 }
开发者ID:ubick,项目名称:glue,代码行数:12,代码来源:Application.php

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

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

    public function testWithBadRequest()
    {
        $requestStack = new RequestStack();

        $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
        $requestMatcher->expects($this->never())->method('matchRequest');

        $dispatcher = new EventDispatcher();
        $dispatcher->addSubscriber(new ValidateRequestListener());
        $dispatcher->addSubscriber(new RouterListener($requestMatcher, $requestStack, new RequestContext()));
        $dispatcher->addSubscriber(new ExceptionListener(function () {
            return new Response('Exception handled', 400);
        }));

        $kernel = new HttpKernel($dispatcher, new ControllerResolver(), $requestStack, new ArgumentResolver());

        $request = Request::create('http://localhost/');
        $request->headers->set('host', '###');
        $response = $kernel->handle($request);
        $this->assertSame(400, $response->getStatusCode());
    }
开发者ID:symfony,项目名称:symfony,代码行数:21,代码来源:RouterListenerTest.php

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

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

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


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