An instance of this class will be passed to each component of the chain allowing them to read/write parameters to/from it. Besides handling of the chain is interrupted as soon as the "cancelled" flag is set. The instance will be created before the bootstrap, so AOP/DI proxying is not possible.
Esempio n. 1
0
 /**
  * Set the routes configuration for the Neos setup and configures the routing component
  * to skip initialisation, which would overwrite the specific settings again.
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $configurationSource = $this->objectManager->get(\Neos\Flow\Configuration\Source\YamlSource::class);
     $routesConfiguration = $configurationSource->load($this->packageManager->getPackage('Neos.Setup')->getConfigurationPath() . ConfigurationManager::CONFIGURATION_TYPE_ROUTES);
     $this->router->setRoutesConfiguration($routesConfiguration);
     $componentContext->setParameter(\Neos\Flow\Mvc\Routing\RoutingComponent::class, 'skipRouterInitialization', true);
 }
 /**
  * @test
  */
 public function handleStoresRouterMatchResultsInTheComponentContext()
 {
     $mockMatchResults = ['someRouterMatchResults'];
     $this->mockRouter->expects($this->atLeastOnce())->method('route')->with($this->mockHttpRequest)->will($this->returnValue($mockMatchResults));
     $this->mockComponentContext->expects($this->atLeastOnce())->method('setParameter')->with(RoutingComponent::class, 'matchResults', $mockMatchResults);
     $this->routingComponent->handle($this->mockComponentContext);
 }
 /**
  * @test
  */
 public function handleResetsTheCancelParameterIfItWasTrue()
 {
     $mockComponent1 = $this->getMockBuilder(Http\Component\ComponentInterface::class)->getMock();
     $this->mockComponentContext->expects($this->at(1))->method('getParameter')->with(Http\Component\ComponentChain::class, 'cancel')->will($this->returnValue(true));
     $this->mockComponentContext->expects($this->at(2))->method('setParameter')->with(Http\Component\ComponentChain::class, 'cancel', null);
     $options = ['components' => [$mockComponent1]];
     $this->componentChain = new Http\Component\ComponentChain($options);
     $this->componentChain->handle($this->mockComponentContext);
 }
 public function setUp()
 {
     $this->mockHttpRequest = $this->getMockBuilder(Http\Request::class)->disableOriginalConstructor()->getMock();
     $this->mockHttpResponse = $this->getMockBuilder(Http\Response::class)->disableOriginalConstructor()->getMock();
     $this->mockComponentContext = $this->getMockBuilder(Http\Component\ComponentContext::class)->disableOriginalConstructor()->getMock();
     $this->mockComponentContext->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->mockHttpRequest));
     $this->mockComponentContext->expects($this->any())->method('getHttpResponse')->will($this->returnValue($this->mockHttpResponse));
     $this->standardsComplianceComponent = new Http\Component\StandardsComplianceComponent([]);
 }
 /**
  * Create an action request from stored route match values and dispatch to that
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     /** @var $actionRequest ActionRequest */
     $actionRequest = $this->objectManager->get(ActionRequest::class, $httpRequest);
     $this->securityContext->setRequest($actionRequest);
     $routingMatchResults = $componentContext->getParameter(Routing\RoutingComponent::class, 'matchResults');
     $actionRequest->setArguments($this->mergeArguments($httpRequest, $routingMatchResults));
     $this->setDefaultControllerAndActionNameIfNoneSpecified($actionRequest);
     $componentContext->setParameter(self::class, 'actionRequest', $actionRequest);
     $this->dispatcher->dispatch($actionRequest, $componentContext->getHttpResponse());
 }
Esempio n. 6
0
 /**
  * Check if the current request match a redirect
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $routingMatchResults = $componentContext->getParameter(RoutingComponent::class, 'matchResults');
     if ($routingMatchResults !== NULL) {
         return;
     }
     $httpRequest = $componentContext->getHttpRequest();
     $response = $this->redirectService->buildResponseIfApplicable($httpRequest);
     if ($response !== null) {
         $componentContext->replaceHttpResponse($response);
         $componentContext->setParameter(ComponentChain::class, 'cancel', true);
     }
 }
 /**
  * @test
  */
 public function handleMergesInternalArgumentsWithRoutingMatchResults()
 {
     $this->mockHttpRequest->expects($this->any())->method('getArguments')->will($this->returnValue(['__internalArgument1' => 'request', '__internalArgument2' => 'request', '__internalArgument3' => 'request']));
     $this->mockHttpRequest->expects(self::any())->method('getContent')->willReturn('requestBody');
     $this->mockPropertyMapper->expects($this->any())->method('convert')->will($this->returnValue(['__internalArgument2' => 'requestBody', '__internalArgument3' => 'requestBody']));
     $this->mockComponentContext->expects($this->atLeastOnce())->method('getParameter')->with(RoutingComponent::class, 'matchResults')->will($this->returnValue(['__internalArgument3' => 'routing']));
     $this->mockActionRequest->expects($this->once())->method('setArguments')->with(['__internalArgument1' => 'request', '__internalArgument2' => 'requestBody', '__internalArgument3' => 'routing']);
     $this->dispatchComponent->handle($this->mockComponentContext);
 }
 /**
  * Check if the current request contains a widget context.
  * If so dispatch it directly, otherwise continue with the next HTTP component.
  *
  * @param ComponentContext $componentContext
  * @return void
  * @throws ComponentException
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     $widgetContext = $this->extractWidgetContext($httpRequest);
     if ($widgetContext === null) {
         return;
     }
     /** @var $actionRequest ActionRequest */
     $actionRequest = $this->objectManager->get(\Neos\Flow\Mvc\ActionRequest::class, $httpRequest);
     $actionRequest->setArguments($this->mergeArguments($httpRequest, array()));
     $actionRequest->setArgument('__widgetContext', $widgetContext);
     $actionRequest->setControllerObjectName($widgetContext->getControllerObjectName());
     $this->setDefaultControllerAndActionNameIfNoneSpecified($actionRequest);
     $this->securityContext->setRequest($actionRequest);
     $this->dispatcher->dispatch($actionRequest, $componentContext->getHttpResponse());
     // stop processing the current component chain
     $componentContext->setParameter(\Neos\Flow\Http\Component\ComponentChain::class, 'cancel', true);
 }
 /**
  * @param ComponentContext $componentContext
  * @return void
  * @api
  */
 public function handle(ComponentContext $componentContext)
 {
     $request = $componentContext->getHttpRequest();
     $trustedRequest = $request->withAttribute(Request::ATTRIBUTE_TRUSTED_PROXY, $this->isFromTrustedProxy($request));
     $trustedRequest = $trustedRequest->withAttribute(Request::ATTRIBUTE_CLIENT_IP, $this->getTrustedClientIpAddress($trustedRequest));
     $protocolHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_PROTOCOL, $trustedRequest);
     if ($protocolHeader !== null) {
         $trustedRequest->getUri()->setScheme($protocolHeader);
     }
     $hostHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_HOST, $trustedRequest);
     if ($hostHeader !== null) {
         $trustedRequest->getUri()->setHost($hostHeader);
     }
     $portHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_PORT, $trustedRequest);
     if ($portHeader !== null) {
         $trustedRequest->getUri()->setPort($portHeader);
     } elseif ($protocolHeader !== null) {
         $trustedRequest->getUri()->setPort(strtolower($protocolHeader) === 'https' ? 443 : 80);
     }
     $componentContext->replaceHttpRequest($trustedRequest);
 }
 /**
  * @test
  */
 public function handleCancelsComponentChainIfWidgetContextIsPresent()
 {
     $mockWidgetId = 'SomeWidgetId';
     $mockControllerObjectName = 'SomeControllerObjectName';
     $this->mockHttpRequest->expects($this->at(0))->method('hasArgument')->with('__widgetId')->will($this->returnValue(true));
     $this->mockHttpRequest->expects($this->atLeastOnce())->method('getArgument')->with('__widgetId')->will($this->returnValue($mockWidgetId));
     $mockWidgetContext = $this->getMockBuilder(\Neos\FluidAdaptor\Core\Widget\WidgetContext::class)->getMock();
     $mockWidgetContext->expects($this->atLeastOnce())->method('getControllerObjectName')->will($this->returnValue($mockControllerObjectName));
     $this->mockAjaxWidgetContextHolder->expects($this->atLeastOnce())->method('get')->with($mockWidgetId)->will($this->returnValue($mockWidgetContext));
     $mockActionRequest = $this->getMockBuilder(\Neos\Flow\Mvc\ActionRequest::class)->disableOriginalConstructor()->getMock();
     $this->mockObjectManager->expects($this->atLeastOnce())->method('get')->with(\Neos\Flow\Mvc\ActionRequest::class)->will($this->returnValue($mockActionRequest));
     $this->mockComponentContext->expects($this->once())->method('setParameter')->with(\Neos\Flow\Http\Component\ComponentChain::class, 'cancel', true);
     $this->ajaxWidgetComponent->handle($this->mockComponentContext);
 }
 /**
  * Just call makeStandardsCompliant on the Response for now
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $response = $componentContext->getHttpResponse();
     $response->makeStandardsCompliant($componentContext->getHttpRequest());
 }
 /**
  * Resolve a route for the request
  *
  * Stores the resolved route values in the ComponentContext to pass them
  * to other components. They can be accessed via ComponentContext::getParameter(outingComponent::class, 'matchResults');
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $matchResults = $this->router->route($componentContext->getHttpRequest());
     $componentContext->setParameter(RoutingComponent::class, 'matchResults', $matchResults);
 }
 /**
  * Returns the HTTP response corresponding to the currently handled request
  *
  * @return Response
  * @api
  */
 public function getHttpResponse()
 {
     return $this->componentContext->getHttpResponse();
 }