/** * @test */ public function getMainRequestReturnsTheTopLevelActionRequestWhoseParentIsTheHttpRequest() { $anotherActionRequest = new ActionRequest($this->actionRequest); $yetAnotherActionRequest = new ActionRequest($anotherActionRequest); $this->assertSame($this->actionRequest, $this->actionRequest->getMainRequest()); $this->assertSame($this->actionRequest, $yetAnotherActionRequest->getMainRequest()); $this->assertSame($this->actionRequest, $anotherActionRequest->getMainRequest()); }
/** * Pass the arguments which were addressed to the plugin to its own request * * @param ActionRequest $pluginRequest The plugin request * @return void */ protected function passArgumentsToPluginRequest(ActionRequest $pluginRequest) { $arguments = $pluginRequest->getMainRequest()->getPluginArguments(); $pluginNamespace = $this->getPluginNamespace(); if (isset($arguments[$pluginNamespace])) { $pluginRequest->setArguments($arguments[$pluginNamespace]); } }
/** * Get a new RequestMatcher for the Request's MainRequest * * @return RequestMatcher * @api */ public function getMainRequest() { $this->addWeight(100000); return new RequestMatcher($this->request->getMainRequest(), $this); }
/** * Returns the top level ActionRequest: the one just below the HTTP request * * @return ActionRequest * @api */ public function getMainRequest() { return $this->parentRequest instanceof HttpRequest ? $this : $this->parentRequest->getMainRequest(); }
/** * @param \Neos\Form\Core\Model\FormDefinition $formDefinition * @param \Neos\Flow\Mvc\ActionRequest $request * @param \Neos\Flow\Http\Response $response * @throws \Neos\Form\Exception\IdentifierNotValidException * @internal */ public function __construct(\Neos\Form\Core\Model\FormDefinition $formDefinition, \Neos\Flow\Mvc\ActionRequest $request, \Neos\Flow\Http\Response $response) { $this->formDefinition = $formDefinition; $rootRequest = $request->getMainRequest() ?: $request; $pluginArguments = $rootRequest->getPluginArguments(); $this->request = new ActionRequest($request); $formIdentifier = $this->formDefinition->getIdentifier(); $this->request->setArgumentNamespace('--' . $formIdentifier); if (isset($pluginArguments[$formIdentifier])) { $this->request->setArguments($pluginArguments[$formIdentifier]); } $this->response = $response; }
/** * Merges specified arguments with arguments from request. * * If $this->request is no sub request, request arguments will only be merged if $this->addQueryString is set. * Otherwise all request arguments except for the ones prefixed with the current request argument namespace will * be merged. Additionally special arguments (PackageKey, SubpackageKey, ControllerName & Action) are merged. * * The argument provided through the $arguments parameter always overrule the request * arguments. * * The request hierarchy is structured as follows: * root (HTTP) > main (Action) > sub (Action) > sub sub (Action) * * @param array $arguments * @return array */ protected function mergeArgumentsWithRequestArguments(array $arguments) { if ($this->request !== $this->request->getMainRequest()) { $subRequest = $this->request; while ($subRequest instanceof ActionRequest) { $requestArguments = (array) $subRequest->getArguments(); // Reset arguments for the request that is bound to this UriBuilder instance if ($subRequest === $this->request) { if ($this->addQueryString === false) { $requestArguments = []; } else { foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) { unset($requestArguments[$argumentToBeExcluded]); } } } else { // Remove all arguments of the current sub request if it's namespaced if ($this->request->getArgumentNamespace() !== '') { $requestNamespace = $this->getRequestNamespacePath($this->request); if ($this->addQueryString === false) { $requestArguments = Arrays::unsetValueByPath($requestArguments, $requestNamespace); } else { foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) { $requestArguments = Arrays::unsetValueByPath($requestArguments, $requestNamespace . '.' . $argumentToBeExcluded); } } } } // Merge special arguments (package, subpackage, controller & action) from main request $requestPackageKey = $subRequest->getControllerPackageKey(); if (!empty($requestPackageKey)) { $requestArguments['@package'] = $requestPackageKey; } $requestSubpackageKey = $subRequest->getControllerSubpackageKey(); if (!empty($requestSubpackageKey)) { $requestArguments['@subpackage'] = $requestSubpackageKey; } $requestControllerName = $subRequest->getControllerName(); if (!empty($requestControllerName)) { $requestArguments['@controller'] = $requestControllerName; } $requestActionName = $subRequest->getControllerActionName(); if (!empty($requestActionName)) { $requestArguments['@action'] = $requestActionName; } if (count($requestArguments) > 0) { $requestArguments = $this->addNamespaceToArguments($requestArguments, $subRequest); $arguments = Arrays::arrayMergeRecursiveOverrule($requestArguments, $arguments); } $subRequest = $subRequest->getParentRequest(); } } elseif ($this->addQueryString === true) { $requestArguments = $this->request->getArguments(); foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) { unset($requestArguments[$argumentToBeExcluded]); } if ($requestArguments !== []) { $arguments = Arrays::arrayMergeRecursiveOverrule($requestArguments, $arguments); } } return $arguments; }
/** * This method generates the Uri through the joinPoint with * temporary overriding the used node * * @param ActionRequest $request * @param JoinPointInterface $joinPoint The current join point * @param NodeInterface $node * @return string $uri */ public function generateUriForNode(ActionRequest $request, JoinPointInterface $joinPoint, NodeInterface $node) { // store original node path to restore it after generating the uri $originalNodePath = $request->getMainRequest()->getArgument('node'); // generate the uri for the given node $request->getMainRequest()->setArgument('node', $node->getContextPath()); $result = $joinPoint->getAdviceChain()->proceed($joinPoint); // restore the original node path $request->getMainRequest()->setArgument('node', $originalNodePath); return $result; }
/** * Calculates the dimensions of the thumbnail to be generated and returns the thumbnail URI. * In case of Images this is a thumbnail of the image, in case of other assets an icon representation. * * @param AssetInterface $asset * @param ThumbnailConfiguration $configuration * @param ActionRequest $request Request argument must be provided for asynchronous thumbnails * @return array|null Array with keys "width", "height" and "src" if the thumbnail generation work or null * @throws AssetServiceException */ public function getThumbnailUriAndSizeForAsset(AssetInterface $asset, ThumbnailConfiguration $configuration, ActionRequest $request = null) { $thumbnailImage = $this->thumbnailService->getThumbnail($asset, $configuration); if (!$thumbnailImage instanceof ImageInterface) { return null; } $resource = $thumbnailImage->getResource(); if ($thumbnailImage instanceof Thumbnail) { $staticResource = $thumbnailImage->getStaticResource(); if ($configuration->isAsync() === true && $resource === null && $staticResource === null) { if ($request === null) { throw new AssetServiceException('Request argument must be provided for async thumbnails.', 1447660835); } $this->uriBuilder->setRequest($request->getMainRequest()); $uri = $this->uriBuilder->reset()->setCreateAbsoluteUri(true)->uriFor('thumbnail', array('thumbnail' => $thumbnailImage), 'Thumbnail', 'Neos.Media'); } else { $uri = $this->thumbnailService->getUriForThumbnail($thumbnailImage); } } else { $uri = $this->resourceManager->getPublicPersistentResourceUri($resource); } return array('width' => $thumbnailImage->getWidth(), 'height' => $thumbnailImage->getHeight(), 'src' => $uri); }