本文整理汇总了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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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();
}
}
示例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());
}
示例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);
}
示例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);
}
示例15: run
public function run()
{
$this->response = $this->kernel->handle($this->request);
$this->response->send();
$this->kernel->terminate($this->request, $this->response);
return $this;
}