コード例 #1
0
 /**
  * Extracts the WidgetContext from the given $httpRequest.
  * If the request contains an argument "__widgetId" the context is fetched from the session (AjaxWidgetContextHolder).
  * Otherwise the argument "__widgetContext" is expected to contain the serialized WidgetContext (protected by a HMAC suffix)
  *
  * @param Request $httpRequest
  * @return WidgetContext
  */
 protected function extractWidgetContext(Request $httpRequest)
 {
     if ($httpRequest->hasArgument('__widgetId')) {
         return $this->ajaxWidgetContextHolder->get($httpRequest->getArgument('__widgetId'));
     } elseif ($httpRequest->hasArgument('__widgetContext')) {
         $serializedWidgetContextWithHmac = $httpRequest->getArgument('__widgetContext');
         $serializedWidgetContext = $this->hashService->validateAndStripHmac($serializedWidgetContextWithHmac);
         return unserialize(base64_decode($serializedWidgetContext));
     }
     return null;
 }
コード例 #2
0
 /**
  * @test
  */
 public function buildSetsWidgetContext()
 {
     $_GET = array('fluid-widget-id' => '123');
     $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->with('123')->will($this->returnValue($this->mockWidgetContext));
     $this->mockWidgetRequest->expects($this->once())->method('setWidgetContext')->with($this->mockWidgetContext);
     $this->widgetRequestBuilder->build();
 }
コード例 #3
0
 /**
  * Builds a widget request object from the raw HTTP information
  *
  * @return \TYPO3\Fluid\Core\Widget\WidgetRequest The widget request as an object
  */
 public function build()
 {
     $request = $this->objectManager->create('TYPO3\\Fluid\\Core\\Widget\\WidgetRequest');
     $request->setRequestURI(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
     $request->setBaseURI(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
     $request->setMethod(isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : NULL);
     if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
         $request->setArguments(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST());
     } else {
         $request->setArguments(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET());
     }
     $rawGetArguments = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET();
     // TODO: rename to @action, to be consistent with normal naming?
     if (isset($rawGetArguments['action'])) {
         $request->setControllerActionName($rawGetArguments['action']);
     }
     $widgetContext = $this->ajaxWidgetContextHolder->get($rawGetArguments['fluid-widget-id']);
     $request->setWidgetContext($widgetContext);
     return $request;
 }
コード例 #4
0
 /**
  * An advice which intercepts the original route() method if a widget AJAX request
  * was identified.
  *
  * If the HTTP request contains an argument hinting on an AJAX request directed
  * to a widget, this method will create a matching ActionRequest rather than
  * invoking the whole routing mechanism.
  *
  * @Flow\Around("method(TYPO3\Flow\Mvc\Routing\Router->route())")
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint
  * @return \TYPO3\Flow\Mvc\ActionRequest
  */
 public function routeAjaxWidgetRequestAdvice(JoinPointInterface $joinPoint)
 {
     $httpRequest = $joinPoint->getMethodArgument('httpRequest');
     if ($httpRequest->hasArgument('__widgetId') || $httpRequest->hasArgument('__widgetContext')) {
         $actionRequest = $httpRequest->createActionRequest();
         $widgetId = $actionRequest->getInternalArgument('__widgetId');
         if ($widgetId !== NULL) {
             $widgetContext = $this->ajaxWidgetContextHolder->get($widgetId);
         } else {
             $serializedWidgetContextWithHmac = $actionRequest->getInternalArgument('__widgetContext');
             $serializedWidgetContext = $this->hashService->validateAndStripHmac($serializedWidgetContextWithHmac);
             $widgetContext = unserialize($serializedWidgetContext);
         }
         $actionRequest->setArgument('__widgetContext', $widgetContext);
         $actionRequest->setControllerObjectName($widgetContext->getControllerObjectName());
         return $actionRequest;
     } else {
         return $joinPoint->getAdviceChain()->proceed($joinPoint);
     }
 }
 /**
  * Initialize the Widget Context, before the Render method is called.
  *
  * @return void
  */
 private function initializeWidgetContext()
 {
     if ($this->ajaxWidget === true) {
         if ($this->storeConfigurationInSession === true) {
             $this->ajaxWidgetContextHolder->store($this->widgetContext);
         }
         $this->widgetContext->setAjaxWidgetConfiguration($this->getAjaxWidgetConfiguration());
     }
     $this->widgetContext->setNonAjaxWidgetConfiguration($this->getNonAjaxWidgetConfiguration());
     $this->initializeWidgetIdentifier();
     $controllerObjectName = $this->controller instanceof DependencyProxy ? $this->controller->_getClassName() : get_class($this->controller);
     $this->widgetContext->setControllerObjectName($controllerObjectName);
 }
 /**
  * @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(\TYPO3\Fluid\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(\TYPO3\Flow\Mvc\ActionRequest::class)->disableOriginalConstructor()->getMock();
     $this->mockObjectManager->expects($this->atLeastOnce())->method('get')->with(\TYPO3\Flow\Mvc\ActionRequest::class)->will($this->returnValue($mockActionRequest));
     $this->mockSecurityContext->expects($this->once())->method('setRequest')->with($mockActionRequest);
     $this->ajaxWidgetComponent->handle($this->mockComponentContext);
 }
コード例 #7
0
 /**
  * Initialize the Widget Context, before the Render method is called.
  *
  * @return void
  */
 private function initializeWidgetContext()
 {
     $this->widgetContext->setWidgetConfiguration($this->getWidgetConfiguration());
     $this->initializeWidgetIdentifier();
     $controllerObjectName = $this->controller instanceof \Tx_Fluid_AOP_ProxyInterface ? $this->controller->FLOW3_AOP_Proxy_getProxyTargetClassName() : get_class($this->controller);
     $this->widgetContext->setControllerObjectName($controllerObjectName);
     $extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
     $pluginName = $this->controllerContext->getRequest()->getPluginName();
     $this->widgetContext->setParentExtensionName($extensionName);
     $this->widgetContext->setParentPluginName($pluginName);
     $pluginNamespace = $this->extensionService->getPluginNamespace($extensionName, $pluginName);
     $this->widgetContext->setParentPluginNamespace($pluginNamespace);
     $this->widgetContext->setWidgetViewHelperClassName(get_class($this));
     if ($this->ajaxWidget === TRUE) {
         $this->ajaxWidgetContextHolder->store($this->widgetContext);
     }
 }
 /**
  * @test
  */
 public function initializeArgumentsAndRenderStoresTheWidgetContextIfInAjaxMode()
 {
     $this->viewHelper->_set('ajaxWidget', TRUE);
     $this->ajaxWidgetContextHolder->expects($this->once())->method('store')->with($this->widgetContext);
     $this->callViewHelper();
 }