/** * @return ControllerContext */ protected function createControllerContextFromEnvironment() { $httpRequest = Request::createFromEnvironment(); /** @var ActionRequest $request */ $request = $httpRequest->createActionRequest(); $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($request); return new ControllerContext($request, new Response(), new Arguments(array()), $uriBuilder); }
/** * Action for creating a temporary account * * @param Registration $registration * @return void */ public function createAccountAction(Registration $registration) { $accountIdentifier = $registration->getUsername(); $existingAccount = $this->accountRepository->findActiveByAccountIdentifierAndAuthenticationProviderName($accountIdentifier, 'Typo3BackendProvider'); if ($existingAccount !== NULL) { $this->addFlashMessage('An account with the username "%s" already exists.', 'Account already exists', Message::SEVERITY_ERROR, array($accountIdentifier)); $this->forward('newAccount'); } $this->createTemporaryAccount($accountIdentifier, $registration->getPassword(), $registration->getFirstName(), $registration->getLastName()); $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($this->request->getParentRequest()); $redirectUri = $uriBuilder->setCreateAbsoluteUri(TRUE)->uriFor('index', array('username' => $accountIdentifier), 'Login', 'TYPO3.Neos'); $this->redirectToUri($redirectUri); }
/** * @return void */ public function setUp() { $this->viewHelperVariableContainer = $this->getMock('TYPO3\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer'); $this->viewHelperVariableContainer->expects($this->any())->method('exists')->will($this->returnCallback(array($this, 'viewHelperVariableContainerExistsCallback'))); $this->viewHelperVariableContainer->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'viewHelperVariableContainerGetCallback'))); $this->templateVariableContainer = $this->getMock('TYPO3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer'); $this->uriBuilder = $this->getMock('TYPO3\\Flow\\Mvc\\Routing\\UriBuilder'); $this->uriBuilder->expects($this->any())->method('reset')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setArguments')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setSection')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setFormat')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setCreateAbsoluteUri')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setAddQueryString')->will($this->returnValue($this->uriBuilder)); $this->uriBuilder->expects($this->any())->method('setArgumentsToBeExcludedFromQueryString')->will($this->returnValue($this->uriBuilder)); // BACKPORTER TOKEN #1 $httpRequest = \TYPO3\Flow\Http\Request::create(new \TYPO3\Flow\Http\Uri('http://localhost/foo')); $this->request = $this->getMock('TYPO3\\Flow\\Mvc\\ActionRequest', array(), array($httpRequest)); $this->request->expects($this->any())->method('isMainRequest')->will($this->returnValue(TRUE)); $this->controllerContext = $this->getMock('TYPO3\\Flow\\Mvc\\Controller\\ControllerContext', array(), array(), '', FALSE); $this->controllerContext->expects($this->any())->method('getUriBuilder')->will($this->returnValue($this->uriBuilder)); $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $this->tagBuilder = $this->getMock('TYPO3\\Fluid\\Core\\ViewHelper\\TagBuilder'); $this->arguments = array(); $this->renderingContext = new \TYPO3\Fluid\Core\Rendering\RenderingContext(); $this->renderingContext->injectTemplateVariableContainer($this->templateVariableContainer); $this->renderingContext->injectViewHelperVariableContainer($this->viewHelperVariableContainer); $this->renderingContext->setControllerContext($this->controllerContext); }
/** * Helper to build a TypoScript view object * * @return TypoScriptView */ protected function buildView() { $view = new TypoScriptView(); $httpRequest = Request::createFromEnvironment(); $request = $httpRequest->createActionRequest(); $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($request); $this->controllerContext = new ControllerContext($request, new Response(), new Arguments(array()), $uriBuilder); $view->setControllerContext($this->controllerContext); $view->disableFallbackView(); $view->setPackageKey('TYPO3.TypoScript'); $view->setTypoScriptPathPattern(__DIR__ . '/Fixtures/TypoScript'); $view->assign('fixtureDirectory', __DIR__ . '/Fixtures/'); return $view; }
/** * @test */ public function setArgumentsSetsNonPrefixedArgumentsByDefault() { $arguments = array('argument1' => 'argument1Value', 'argument2' => array('argument2a' => 'argument2aValue')); $this->uriBuilder->setArguments($arguments); $expectedResult = $arguments; $this->assertEquals($expectedResult, $this->uriBuilder->getArguments()); }
/** * @param ActionRequest $request * @return string */ protected function buildActionUri(ActionRequest $request) { $packageKey = $this->parseOption('package'); $controllerName = $this->parseOption('controller'); $actionName = $this->parseOption('action'); $arguments = $this->parseOption('arguments'); $subpackageKey = null; if ($packageKey !== null && strpos($packageKey, '\\') !== false) { list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2); } $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($request); $uriBuilder->reset(); $uri = $uriBuilder->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey); return $uri; }
/** * @return void * @throws ForwardException */ public function executeInternal() { $formRuntime = $this->finisherContext->getFormRuntime(); $request = $formRuntime->getRequest()->getMainRequest(); $this->uriBuilder->setRequest($request); $uri = null; $path = $this->parseOption('path'); $action = $this->parseOption('action'); $format = $this->parseOption('format'); $modifiedArguments = ['module' => $path]; if ($action !== null) { $modifiedArguments['moduleArguments']['@action'] = $action; } $jobIdentifier = $formRuntime->getRequest()->getArgument('jobIdentifier'); $options = $formRuntime->getRequest()->getArguments(); unset($options['jobIdentifier']); $this->executeJob($jobIdentifier, $options); $uri = $this->uriBuilder->reset()->setCreateAbsoluteUri(true)->setFormat($format)->uriFor('index', $modifiedArguments, 'Backend\\Module', 'TYPO3.Neos'); $this->redirect($uri); }
/** * Merging the configuration of the Settings.yaml with some default values for OPAuth * * @param array $configuration * @return array */ protected function createConfiguration(array $configuration) { $route = $configuration['authenticationControllerRoute']; $opauthBasePath = $this->uriBuilder->uriFor('opauth', array('strategy' => ''), $this->getRoutePart($route, '@controller'), $this->getRoutePart($route, '@package'), $this->getRoutePart($route, '@subpackage')); $opauthCallbackPath = $this->uriBuilder->uriFor('authenticate', array(), $this->getRoutePart($route, '@controller'), $this->getRoutePart($route, '@package'), $this->getRoutePart($route, '@subpackage')); $opauthConfiguration = array(); $opauthConfiguration['defaultRoleIdentifier'] = $configuration['defaultRoleIdentifier']; $opauthConfiguration['authenticationProviderName'] = $configuration['authenticationProviderName']; // should be created with UriBuilder $opauthConfiguration['path'] = $opauthBasePath; // should be created with UriBuilder $opauthConfiguration['callback_url'] = $opauthCallbackPath; // it must be 'post' $opauthConfiguration['callback_transport'] = 'post'; // the security salt $opauthConfiguration['security_salt'] = $configuration['securitySalt']; // the strategy directory $opauthConfiguration['strategy_dir'] = $this->getStrategyDirectory($configuration); // import all strategy settings $opauthConfiguration['Strategy'] = $configuration['strategies']; return $opauthConfiguration; }
/** * Returns the body and header sections created by the clients configured for the given page name. * * @param \TYPO3\Flow\Mvc\RequestInterface $request Request object * @param string $pageName Name of the configured page * @return array Associative list with body and header output separated by client name */ public function getSections(\TYPO3\Flow\Mvc\RequestInterface $request, $pageName) { $this->uriBuilder->setRequest($request); $tmplPaths = $this->aimeos->get()->getCustomPaths('client/html/templates'); $pagesConfig = $this->settings['page']; $result = array('aibody' => array(), 'aiheader' => array()); $context = $this->context->get($request); $langid = $context->getLocale()->getLanguageId(); $view = $this->view->create($context, $this->uriBuilder, $tmplPaths, $request, $langid); $context->setView($view); if (isset($pagesConfig[$pageName])) { foreach ((array) $pagesConfig[$pageName] as $clientName) { $client = \Aimeos\Client\Html\Factory::createClient($context, $tmplPaths, $clientName); $client->setView(clone $view); $client->process(); $varName = str_replace('/', '_', $clientName); $result['aibody'][$varName] = $client->getBody(); $result['aiheader'][$varName] = $client->getHeader(); } } return $result; }
/** * @test */ public function callingRenderAssignsVariablesCorrectlyToUriBuilder() { $this->uriBuilder->expects($this->once())->method('setSection')->with('section')->will($this->returnSelf()); $this->uriBuilder->expects($this->once())->method('setArguments')->with(array('additionalParams'))->will($this->returnSelf()); $this->uriBuilder->expects($this->once())->method('setArgumentsToBeExcludedFromQueryString')->with(array('argumentsToBeExcludedFromQueryString'))->will($this->returnSelf()); $this->uriBuilder->expects($this->once())->method('setFormat')->with('format')->will($this->returnSelf()); $expectedModifiedArguments = array('module' => 'the/path', 'moduleArguments' => array('arguments', '@action' => 'action')); $this->uriBuilder->expects($this->once())->method('uriFor')->with('index', $expectedModifiedArguments); // fallback for the method chaining of the URI builder $this->uriBuilder->expects($this->any())->method($this->anything())->will($this->returnValue($this->uriBuilder)); $this->viewHelper->render('the/path', 'action', array('arguments'), 'section', 'format', array('additionalParams'), true, array('argumentsToBeExcludedFromQueryString')); }
/** * Starts the authentication: Redirect to login page * * @param \TYPO3\Flow\Http\Request $request The current request * @param \TYPO3\Flow\Http\Response $response The current response * @return void * @throws MissingConfigurationException */ public function startAuthentication(Request $request, Response $response) { if (isset($this->options['routeValues'])) { $routeValues = $this->options['routeValues']; if (!is_array($routeValues)) { throw new MissingConfigurationException(sprintf('The configuration for the WebRedirect authentication entry point is incorrect. "routeValues" must be an array, got "%s".', gettype($routeValues)), 1345040415); } $actionRequest = new ActionRequest($request); $this->uriBuilder->setRequest($actionRequest); $actionName = $this->extractRouteValue($routeValues, '@action'); $controllerName = $this->extractRouteValue($routeValues, '@controller'); $packageKey = $this->extractRouteValue($routeValues, '@package'); $subPackageKey = $this->extractRouteValue($routeValues, '@subpackage'); $uri = $this->uriBuilder->setCreateAbsoluteUri(true)->uriFor($actionName, $routeValues, $controllerName, $packageKey, $subPackageKey); } elseif (isset($this->options['uri'])) { $uri = strpos($this->options['uri'], '://') !== false ? $this->options['uri'] : $request->getBaseUri() . $this->options['uri']; } else { throw new MissingConfigurationException('The configuration for the WebRedirect authentication entry point is incorrect or missing. You need to specify either the target "uri" or "routeValues".', 1237282583); } $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlentities($uri, ENT_QUOTES, 'utf-8'))); $response->setStatus(303); $response->setHeader('Location', $uri); }
/** * 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', 'TYPO3.Media'); } else { $uri = $this->thumbnailService->getUriForThumbnail($thumbnailImage); } } else { $uri = $this->resourceManager->getPublicPersistentResourceUri($resource); } return array('width' => $thumbnailImage->getWidth(), 'height' => $thumbnailImage->getHeight(), 'src' => $uri); }
/** * Redirects the request to another action and / or controller. * * Redirect will be sent to the client which then performs another request to the new URI. * * NOTE: This method only supports web requests and will throw an exception * if used with other request types. * * @param string $actionName Name of the action to forward to * @param string $controllerName Unqualified object name of the controller to forward to. If not specified, the current controller is used. * @param string $packageKey Key of the package containing the controller to forward to. If not specified, the current package is assumed. * @param array $arguments Array of arguments for the target action * @param integer $delay (optional) The delay in seconds. Default is no delay. * @param integer $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other" * @param string $format The format to use for the redirect URI * @return void * @throws \TYPO3\Flow\Mvc\Exception\StopActionException * @see forward() * @api */ protected function redirect($actionName, $controllerName = null, $packageKey = null, array $arguments = null, $delay = 0, $statusCode = 303, $format = null) { if ($packageKey !== null && strpos($packageKey, '\\') !== false) { list($packageKey, $subpackageKey) = explode('\\', $packageKey, 2); } else { $subpackageKey = null; } $this->uriBuilder->reset(); if ($format === null) { $this->uriBuilder->setFormat($this->request->getFormat()); } else { $this->uriBuilder->setFormat($format); } $uri = $this->uriBuilder->setCreateAbsoluteUri(true)->uriFor($actionName, $arguments, $controllerName, $packageKey, $subpackageKey); $this->redirectToUri($uri, $delay, $statusCode); }
/** * The Resource Information most likely needs an UriBuilder, so having a * ControllerContext in place might come in handy. * * @return void */ protected function initializeControllerContext() { $request = new ActionRequest(Request::createFromEnvironment()); $request->setDispatched(true); $response = new Response(); $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($request); $arguments = new Arguments(array()); $this->controllerContext = new ControllerContext($request, $response, $arguments, $uriBuilder); }
/** * Initiates the StandaloneView by creating the required ControllerContext * * @return void */ public function initializeObject() { if ($this->request === NULL) { $httpRequest = Request::createFromEnvironment(); $this->request = $this->objectManager->get(\TYPO3\Flow\Mvc\ActionRequest::class, $httpRequest); } $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($this->request); $this->setControllerContext(new ControllerContext($this->request, new Response(), new Arguments(array()), $uriBuilder)); }
/** * Initiates the StandaloneView by creating the required ControllerContext * * @return void */ public function initializeObject() { if ($this->request === NULL) { $httpRequest = Request::createFromEnvironment(); $this->request = $httpRequest->createActionRequest(); } $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($this->request); $this->setControllerContext(new ControllerContext($this->request, new Response(), new Arguments(array()), $uriBuilder, $this->flashMessageContainer)); }
/** * Creates a new blog post node * * @return void */ public function createAction() { /** @var NodeInterface $blogDocumentNode */ $blogDocumentNode = $this->request->getInternalArgument('__documentNode'); if ($blogDocumentNode === NULL) { return 'Error: The Blog Post Plugin cannot determine the current document node. Please make sure to include this plugin only by inserting it into a page / document.'; } $contentContext = $blogDocumentNode->getContext(); $nodeTemplate = new NodeTemplate(); $nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType('RobertLemke.Plugin.Blog:Post')); $nodeTemplate->setProperty('title', 'A new blog post'); $nodeTemplate->setProperty('datePublished', $contentContext->getCurrentDateTime()); $slug = uniqid('post'); $postNode = $blogDocumentNode->createNodeFromTemplate($nodeTemplate, $slug); $currentlyFirstPostNode = $blogDocumentNode->getPrimaryChildNode(); if ($currentlyFirstPostNode !== NULL) { // FIXME This currently doesn't work, probably due to some TYPO3CR bug / misconception $postNode->moveBefore($currentlyFirstPostNode); } $mainRequest = $this->request->getMainRequest(); $mainUriBuilder = new UriBuilder(); $mainUriBuilder->setRequest($mainRequest); $mainUriBuilder->setFormat('html'); $uri = $mainUriBuilder->reset()->setCreateAbsoluteUri(TRUE)->uriFor('show', array('node' => $postNode)); $this->redirectToUri($uri); }
/** * Returns a specific URI string to redirect to after the logout; or NULL if there is none. * In case of NULL, it's the responsibility of the AuthenticationController where to redirect, * most likely to the LoginController's index action. * * @param ActionRequest $actionRequest * @return string A possible redirection URI, if any */ public function getAfterLogoutRedirectionUri(ActionRequest $actionRequest) { $lastVisitedNode = $this->getLastVisitedNode('live'); if ($lastVisitedNode === null) { return null; } $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($actionRequest); $uriBuilder->setFormat('html'); $uriBuilder->setCreateAbsoluteUri(true); return $uriBuilder->uriFor('show', array('node' => $lastVisitedNode), 'Frontend\\Node', 'TYPO3.Neos'); }
/** * Extracted out to this method in order to be better unit-testable. * * @return void */ protected function setMainRequestToUriBuilder() { $mainRequest = $this->controllerContext->getRequest()->getMainRequest(); $this->uriBuilder->setRequest($mainRequest); }