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


PHP KernelInterface::handle方法代码示例

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


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

示例1: onMessage

 /**
  * Triggered when a client sends data through the socket
  * @param  \Ratchet\ConnectionInterface $from The socket/connection that sent the message to your application
  * @param  string $message The message received
  * @throws \Exception
  */
 function onMessage(ConnectionInterface $from, $message)
 {
     $json = json_decode($message, true, 2);
     $ticket = $json['ticket'];
     $method = $json['method'];
     $requestContent = $json['request'];
     // Dispatch request.
     $server = ['REQUEST_METHOD' => $method, 'REQUEST_URI' => '/data/', 'SERVER_PORT' => 843, 'HTTP_HOST' => 'localhost:843', 'HTTP_ACCEPT' => 'application/json'];
     $request = new Request([], [], [], [], [], $server, $requestContent);
     $response = $this->kernel->handle($request);
     // Send back response.
     $websocketData = json_encode(['ticket' => $ticket, 'status' => $response->getStatusCode(), 'response' => $response->getContent()]);
     $from->send($websocketData);
 }
开发者ID:CornyPhoenix,项目名称:JsEntitiesBundle,代码行数:20,代码来源:RESTMessageComponent.php

示例2: doRequest

 /**
  * Do request
  *
  * @param string $route      route
  * @param mixed  $content    content
  * @param string $method     method
  * @param array  $parameters Parameters
  *
  * @return Response
  */
 private function doRequest($route, $content, $method = 'POST', $parameters = [])
 {
     if ($content instanceof ArrayCollection) {
         $content = $this->collectionToArray($content);
     }
     $master = $this->requestStack->getMasterRequest();
     $uri = $this->router->generate($route, $parameters, Router::ABSOLUTE_URL);
     $request = $master->create($uri, $method, [], [], [], $master->server->all(), json_encode($content));
     return $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST);
 }
开发者ID:RomanShumkov,项目名称:EcentriaRestBundle,代码行数:20,代码来源:RequestCreator.php

示例3: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $data = $event->getControllerResult();
     $request = $event->getRequest();
     if (!$event->getRequest()->attributes->get('_jarves_is_plugin')) {
         //we accept only plugin responses.
         return;
     }
     $content = $request->attributes->get('_content');
     if (null !== $data) {
         if ($data instanceof PluginResponseInterface) {
             $response = $data;
         } else {
             $response = $this->pageResponseFactory->createPluginResponse($data);
         }
         //it's required to place a PluginResponseInterface as response, so
         //PluginResponseListener::onKernelResponse can correctly identify it
         //and set it as response for this plugin content, so ContentTypes\TypePlugin
         //can place the correct response at the correct position, without executing
         //the plugin twice.
         $event->setResponse($response);
     } else {
         //we hit a plugin route, but it has responsed with NULL
         //this means it is not responsible for this route/slug.
         //we need now to remove this plugin route from the route collection
         //and fire again a sub request until all plugins on this page
         //are handled. If no plugin is responsible for this url pattern
         //and the main page route is also not responsible
         //no response is set in the $event and a 404 is thrown by the HttpKernel.
         $foundRoute = false;
         $routes = $this->frontendRouteListener->getRoutes();
         foreach ($routes as $idx => $route) {
             /** @var \Symfony\Component\Routing\Route $route */
             if ($content === $route->getDefault('_content')) {
                 //remove exactly only the current plugin that was hit in this sub request
                 $routes->remove($idx);
                 $foundRoute = true;
                 break;
             }
         }
         if ($foundRoute) {
             //we've removed the route and fire now again a sub request
             $request = clone $this->pageStack->getRequest();
             $request->attributes = new ParameterBag();
             $response = $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST);
             $event->setResponse($response);
         }
         //we do not need to restore routes in the frontendRouteListener, because
         //it reload all routes on every master request
     }
 }
开发者ID:jarves,项目名称:jarves,代码行数:51,代码来源:PluginResponseListener.php

示例4: doRequest

 /**
  * {@inheritdoc}
  */
 protected function doRequest($request)
 {
     if ($this->hasPerformedRequest) {
         $this->kernel->shutdown();
         $this->kernel->boot();
     } else {
         $this->hasPerformedRequest = true;
     }
     $this->refreshDoctrineConnection();
     $response = $this->kernel->handle($request);
     if ($this->kernel instanceof TerminableInterface) {
         $this->kernel->terminate($request, $response);
     }
     return $response;
 }
开发者ID:Maksold,项目名称:platform,代码行数:18,代码来源:Client.php

示例5: manageRequest

 /**
  * Manages a request, made to the Http server.
  *
  * @param \React\Http\Request $request
  * @param \React\Http\Response $response
  */
 public function manageRequest($request, $response)
 {
     $requestData = [$request->getHeaders()['Host'] . $request->getPath(), $request->getMethod(), array_merge($request->getQuery(), $request->getPost()), [], $request->getFiles(), []];
     $contentType = isset($request->getHeaders()['Content-Type']) ? $request->getHeaders()['Content-Type'] : 'application/x-www-form-urlencoded';
     if (strtolower($contentType) == 'application/x-www-form-urlencoded') {
         $requestData[] = http_build_query($request->getPost());
     } else {
         $requestData[] = $request->getBody();
     }
     //Creates the Symfony Request from the React Request.
     $sRequest = Request::create(...$requestData);
     /** @var Response $sResponse */
     $sResponse = $this->kernel->handle($sRequest);
     $response->writeHead($sResponse->getStatusCode());
     $response->end($sResponse->getContent());
 }
开发者ID:naroga,项目名称:foreman,代码行数:22,代码来源:Processor.php

示例6: render

 public function render()
 {
     if ($response = $this->pageStack->getPageResponse()->getPluginResponse($this->getContent())) {
         return $response->getContent();
     } elseif ($this->plugin) {
         $config = $this->jarves->getConfig($this->bundleName);
         if (!$config) {
             return sprintf('Bundle `%s` does not exist. You probably have to install this bundle.', $this->bundleName);
         }
         if ($this->pluginDef = $config->getPlugin($this->plugin['plugin'])) {
             $controller = $this->pluginDef->getController();
             if ($this->isPreview()) {
                 if (!$this->pluginDef->isPreview()) {
                     //plugin does not allow to have a preview on the actual action method
                     return ($config->getLabel() ?: $config->getBundleName()) . ': ' . $this->pluginDef->getLabel();
                 }
             }
             //create a sub request
             $request = new Request();
             $request->attributes->add(array('_controller' => $controller, '_content' => $this->getContent(), '_jarves_is_plugin' => true, 'options' => isset($this->plugin['options']) ? $this->plugin['options'] : array()));
             $dispatcher = $this->eventDispatcher;
             $callable = array($this, 'exceptionHandler');
             $fixResponse = array($this, 'fixResponse');
             $dispatcher->addListener(KernelEvents::EXCEPTION, $callable, 100);
             $dispatcher->addListener(KernelEvents::VIEW, $fixResponse, 100);
             ob_start();
             $response = $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST);
             //EventListener\PluginRequestListener converts all PluginResponse objects to PageResponses
             if ($response instanceof PageResponse) {
                 if ($pluginResponse = $response->getPluginResponse($this->getContent()->getId())) {
                     $response = $pluginResponse;
                 }
             }
             //                if ($response instanceof PageResponse) {
             //                    if ($response->getPluginResponse($this->getContent()->getId())) {
             //                        $response = $response->getPluginResponse($this->getContent()->getId());
             //                    }
             //                }
             $ob = ob_get_clean();
             $dispatcher->removeListener(KernelEvents::EXCEPTION, $callable);
             $dispatcher->removeListener(KernelEvents::VIEW, $fixResponse);
             return trim($ob) . $response->getContent();
         } else {
             return sprintf('Plugin `%s` in bundle `%s` does not exist. You probably have to install the bundle first.', $this->plugin['plugin'], $this->bundleName);
         }
     }
 }
开发者ID:jarves,项目名称:jarves,代码行数:47,代码来源:TypePlugin.php

示例7: run

 /**
  * Run the application and send the response.
  *
  * @param HttpRequest|null  $request
  * @param HttpResponse|null $response
  *
  * @throws \Exception
  *
  * @return HttpResponse
  */
 public function run(HttpRequest $request = null, HttpResponse $response = null)
 {
     if (false === $this->booted) {
         $this->boot();
     }
     if (null === $request) {
         $request = HttpRequest::createFromGlobals();
     }
     if (null === $response) {
         $response = new HttpResponse();
     }
     // Create a copy of request, as it's by-ref passed into $this->dispatch() and gets modified.
     $cleanRequest = clone $request;
     try {
         $response = $this->dispatch($request, $response);
     } catch (ResourceNotFoundException $e) {
         if ($this->symfonyKernel === null) {
             throw $e;
         }
         $response = $this->symfonyKernel->handle($cleanRequest);
     }
     $response->send();
     return $response;
 }
开发者ID:ppi,项目名称:framework,代码行数:34,代码来源:App.php

示例8: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     return $this->kernel->handle($request, $type, $catch);
 }
开发者ID:Maksold,项目名称:platform,代码行数:7,代码来源:KernelProxy.php


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