Neos\FluidAdaptor\Core\Widget\AjaxWidgetComponent::handle PHP Method

handle() public method

If so dispatch it directly, otherwise continue with the next HTTP component.
public handle ( ComponentContext $componentContext ) : void
$componentContext Neos\Flow\Http\Component\ComponentContext
return void
    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);
    }

Usage Example

コード例 #1
0
 /**
  * @test
  */
 public function handleInjectsActionRequestToSecurityContext()
 {
     $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->mockSecurityContext->expects($this->once())->method('setRequest')->with($mockActionRequest);
     $this->ajaxWidgetComponent->handle($this->mockComponentContext);
 }