/** * 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()); }
/** * Lists all available users. */ public function listUsersCommand() { // If we're in Neos context, we pass on the command. if ($this->shouldUseNeosService()) { $cliRequest = new Request($this->request); $cliRequest->setControllerObjectName(UserCommandController::class); $cliRequest->setControllerCommandName('list'); $cliResponse = new Response($this->response); $this->dispatcher->dispatch($cliRequest, $cliResponse); return; } /** @var User[] $users */ $users = $this->userRepository->findAll()->toArray(); usort($users, function ($a, $b) { /** @var User $a */ /** @var User $b */ return $a->getEmail() > $b->getEmail(); }); $tableRows = []; $headerRow = ['Email', 'Name', 'Role(s)']; foreach ($users as $user) { $tableRows[] = [$user->getEmail(), $user->getFullName(), implode(' ,', $user->getAccount()->getRoles())]; } $this->output->outputTable($tableRows, $headerRow); $this->outputLine(sprintf(' <b>%s users total.</b>', count($users))); }
/** * @test */ public function handleDispatchesTheRequest() { $this->mockHttpRequest->expects($this->any())->method('getArguments')->will($this->returnValue(array())); $this->mockPropertyMapper->expects($this->any())->method('convert')->with('', 'array', $this->mockPropertyMappingConfiguration)->will($this->returnValue(array())); $this->mockDispatcher->expects($this->once())->method('dispatch')->with($this->mockActionRequest, $this->mockHttpResponse); $this->dispatchComponent->handle($this->mockComponentContext); }
/** * @param array $module * @return mixed */ public function indexAction(array $module) { $moduleRequest = new ActionRequest($this->request); $moduleRequest->setArgumentNamespace('moduleArguments'); $moduleRequest->setControllerObjectName($module['controller']); $moduleRequest->setControllerActionName($module['action']); if (isset($module['format'])) { $moduleRequest->setFormat($module['format']); } if ($this->request->hasArgument($moduleRequest->getArgumentNamespace()) === true && is_array($this->request->getArgument($moduleRequest->getArgumentNamespace()))) { $moduleRequest->setArguments($this->request->getArgument($moduleRequest->getArgumentNamespace())); } foreach ($this->request->getPluginArguments() as $argumentNamespace => $argument) { $moduleRequest->setArgument('--' . $argumentNamespace, $argument); } $modules = explode('/', $module['module']); $moduleConfiguration = Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $modules)); $moduleConfiguration['path'] = $module['module']; if (!$this->menuHelper->isModuleEnabled($moduleConfiguration['path'])) { throw new DisabledModuleException(sprintf('The module "%s" is disabled. You can enable it with the "enabled" flag in Settings.yaml.', $module['module']), 1437148922); } $moduleBreadcrumb = array(); $path = array(); foreach ($modules as $moduleIdentifier) { array_push($path, $moduleIdentifier); $config = Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $path)); $moduleBreadcrumb[implode('/', $path)] = $config; } $moduleRequest->setArgument('__moduleConfiguration', $moduleConfiguration); $moduleResponse = new Response($this->response); $this->dispatcher->dispatch($moduleRequest, $moduleResponse); if ($moduleResponse->hasHeader('Location')) { $this->redirectToUri($moduleResponse->getHeader('Location'), 0, $moduleResponse->getStatusCode()); } elseif ($moduleRequest->getFormat() !== 'html') { $mediaType = MediaTypes::getMediaTypeFromFilename('file.' . $moduleRequest->getFormat()); if ($mediaType !== 'application/octet-stream') { $this->controllerContext->getResponse()->setHeader('Content-Type', $mediaType); } return $moduleResponse->getContent(); } else { $user = $this->securityContext->getPartyByType('TYPO3\\Neos\\Domain\\Model\\User'); $sites = $this->menuHelper->buildSiteList($this->controllerContext); $this->view->assignMultiple(array('moduleClass' => implode('-', $modules), 'moduleContents' => $moduleResponse->getContent(), 'title' => $moduleRequest->hasArgument('title') ? $moduleRequest->getArgument('title') : $moduleConfiguration['label'], 'rootModule' => array_shift($modules), 'submodule' => array_shift($modules), 'moduleConfiguration' => $moduleConfiguration, 'moduleBreadcrumb' => $moduleBreadcrumb, 'user' => $user, 'modules' => $this->menuHelper->buildModuleList($this->controllerContext), 'sites' => $sites)); } }
/** * @param string $path * @return string * @throws \Exception */ public function render($path = NULL) { /** @var RequestHandler $activeRequestHandler */ $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); $parentHttpRequest = $activeRequestHandler->getHttpRequest(); $httpRequest = Request::create(new Uri($parentHttpRequest->getBaseUri() . $path . '.html')); $matchingRoute = $this->router->route($httpRequest); if (!$matchingRoute) { throw new \Exception(sprintf('Uri with path "%s" could not be found.', $parentHttpRequest->getBaseUri() . $path . '.html'), 1426446160); } $request = new ActionRequest($parentHttpRequest); foreach ($matchingRoute as $argumentName => $argumentValue) { $request->setArgument($argumentName, $argumentValue); } $response = new Response($activeRequestHandler->getHttpResponse()); $this->dispatcher->dispatch($request, $response); return $response->getContent(); }
/** * @test * @expectedException \TYPO3\Flow\Mvc\Exception\InfiniteLoopException */ public function dispatchThrowsAnInfiniteLoopExceptionIfTheRequestCouldNotBeDispachedAfter99Iterations() { $requestCallCounter = 0; $requestCallBack = function () use(&$requestCallCounter) { return $requestCallCounter++ < 101 ? FALSE : TRUE; }; $this->mockRequest->expects($this->any())->method('isDispatched')->will($this->returnCallBack($requestCallBack, '__invoke')); $this->dispatcher->dispatch($this->mockRequest, $this->mockResponse); }
/** * Returns the rendered content of this plugin * * @return string The rendered content as a string */ public function evaluate() { $currentContext = $this->tsRuntime->getCurrentContext(); $this->node = $currentContext['node']; $this->documentNode = $currentContext['documentNode']; /** @var $parentResponse Response */ $parentResponse = $this->tsRuntime->getControllerContext()->getResponse(); $pluginResponse = new Response($parentResponse); $this->dispatcher->dispatch($this->buildPluginRequest(), $pluginResponse); return $pluginResponse->getContent(); }
/** * Sends the given HTTP request * * @param \TYPO3\Flow\Http\Request $request * @return \TYPO3\Flow\Http\Response * @throws \TYPO3\Flow\Http\Exception * @api */ public function sendRequest(Request $request) { $requestHandler = $this->bootstrap->getActiveRequestHandler(); if (!$requestHandler instanceof \TYPO3\Flow\Tests\FunctionalTestRequestHandler) { throw new \TYPO3\Flow\Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749); } $response = new Response(); $requestHandler->setHttpRequest($request); $requestHandler->setHttpResponse($response); try { $actionRequest = $this->router->route($request); $this->securityContext->clearContext(); $this->securityContext->setRequest($actionRequest); $this->validatorResolver->reset(); $this->dispatcher->dispatch($actionRequest, $response); $session = $this->bootstrap->getObjectManager()->get('TYPO3\\Flow\\Session\\SessionInterface'); if ($session->isStarted()) { $session->close(); } } catch (\Exception $exception) { $pathPosition = strpos($exception->getFile(), 'Packages/'); $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; $content = PHP_EOL . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL; $content .= 'thrown in file ' . $filePathAndName . PHP_EOL; $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL; $content .= \TYPO3\Flow\Error\Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL; if ($exception instanceof \TYPO3\Flow\Exception) { $statusCode = $exception->getStatusCode(); } else { $statusCode = 500; } $response->setStatus($statusCode); $response->setContent($content); $response->setHeader('X-Flow-ExceptionCode', $exception->getCode()); $response->setHeader('X-Flow-ExceptionMessage', $exception->getMessage()); } return $response; }
/** * @test */ public function handleDispatchesActionRequestIfWidgetContextIsPresent() { $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->mockDispatcher->expects($this->once())->method('dispatch')->with($mockActionRequest, $this->mockHttpResponse); $this->ajaxWidgetComponent->handle($this->mockComponentContext); }
/** * Returns the rendered content of this plugin * * @return string The rendered content as a string */ public function evaluate() { $currentContext = $this->tsRuntime->getCurrentContext(); $this->node = $currentContext['node']; $this->documentNode = $currentContext['documentNode']; /** @var $parentResponse Response */ $parentResponse = $this->tsRuntime->getControllerContext()->getResponse(); $pluginResponse = new Response($parentResponse); $this->dispatcher->dispatch($this->buildPluginRequest(), $pluginResponse); foreach ($pluginResponse->getHeaders()->getAll() as $key => $value) { $parentResponse->getHeaders()->set($key, $value, true); } return $pluginResponse->getContent(); }
/** * Returns the rendered content of this plugin * * @return string The rendered content as a string */ public function evaluate() { try { $currentContext = $this->tsRuntime->getCurrentContext(); $this->node = $currentContext['node']; $this->documentNode = $currentContext['documentNode']; /** @var $parentResponse Response */ $parentResponse = $this->tsRuntime->getControllerContext()->getResponse(); $pluginResponse = new Response($parentResponse); $this->dispatcher->dispatch($this->buildPluginRequest(), $pluginResponse); $content = $pluginResponse->getContent(); } catch (\Exception $exception) { $content = $this->tsRuntime->handleRenderingException($this->path, $exception); } return $content; }
/** * Handles a command line request. * * While booting, the Object Manager is not yet available for retrieving the CommandExceptionHandler. * For this purpose, possible occurring exceptions at this stage are caught manually and treated the * same way the CommandExceptionHandler treats exceptions on itself anyways. * * @return void */ public function handleRequest() { try { $runLevel = $this->bootstrap->isCompiletimeCommand(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '') ? 'Compiletime' : 'Runtime'; $this->boot($runLevel); $this->objectManager->get('TYPO3\\Flow\\Cli\\CommandExceptionHandler'); } catch (\Exception $exception) { \TYPO3\Flow\Cli\CommandExceptionHandler::writeResponseAndExit($exception); } $commandLine = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); $this->request = $this->objectManager->get('TYPO3\\Flow\\Cli\\RequestBuilder')->build(array_slice($commandLine, 1)); $this->response = new Response(); $this->exitIfCompiletimeCommandWasNotCalledCorrectly($runLevel); $this->dispatcher->dispatch($this->request, $this->response); $this->response->send(); $this->shutdown($runLevel); }
/** * Handles a HTTP request * * @return void */ public function handleRequest() { // Create the request very early so the Resource Management has a chance to grab it: $this->request = Request::createFromEnvironment(); $this->response = new Response(); $this->boot(); $this->resolveDependencies(); $this->request->injectSettings($this->settings); $this->router->setRoutesConfiguration($this->routesConfiguration); $actionRequest = $this->router->route($this->request); $this->securityContext->setRequest($actionRequest); $this->dispatcher->dispatch($actionRequest, $this->response); $this->response->makeStandardsCompliant($this->request); $this->response->send(); $this->bootstrap->shutdown('Runtime'); $this->exit->__invoke(); }
/** * Handles a command line request. * * While booting, the Object Manager is not yet available for retrieving the CommandExceptionHandler. * For this purpose, possible occurring exceptions at this stage are caught manually and treated the * same way the CommandExceptionHandler treats exceptions on itself anyways. * * @return void */ public function handleRequest() { $runLevel = $this->bootstrap->isCompiletimeCommand(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '') ? Bootstrap::RUNLEVEL_COMPILETIME : Bootstrap::RUNLEVEL_RUNTIME; $this->boot($runLevel); $commandLine = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); $this->request = $this->objectManager->get(\TYPO3\Flow\Cli\RequestBuilder::class)->build(array_slice($commandLine, 1)); $this->response = new Response(); $this->exitIfCompiletimeCommandWasNotCalledCorrectly($runLevel); if ($runLevel === Bootstrap::RUNLEVEL_RUNTIME) { /** @var Context $securityContext */ $securityContext = $this->objectManager->get(\TYPO3\Flow\Security\Context::class); $securityContext->withoutAuthorizationChecks(function () { $this->dispatcher->dispatch($this->request, $this->response); }); } else { $this->dispatcher->dispatch($this->request, $this->response); } $this->response->send(); $this->shutdown($runLevel); }
/** * Handles a command line request. * * While booting, the Object Manager is not yet available for retrieving the CommandExceptionHandler. * For this purpose, possible occurring exceptions at this stage are caught manually and treated the * same way the CommandExceptionHandler treats exceptions on itself anyways. * * @return void */ public function handleRequest() { $runLevel = $this->bootstrap->isCompiletimeCommand(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '') ? 'Compiletime' : 'Runtime'; $this->boot($runLevel); $commandLine = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); $this->request = $this->objectManager->get('TYPO3\\Flow\\Cli\\RequestBuilder')->build(array_slice($commandLine, 1)); $this->response = new Response(); $this->exitIfCompiletimeCommandWasNotCalledCorrectly($runLevel); if ($runLevel === 'Runtime') { /** @var \TYPO3\Flow\Security\Context $securityContext */ $securityContext = $this->objectManager->get('TYPO3\\Flow\\Security\\Context'); $dispatcher = $this->dispatcher; $request = $this->request; $response = $this->response; $securityContext->withoutAuthorizationChecks(function () use($dispatcher, $request, $response) { $dispatcher->dispatch($request, $response); }); } else { $this->dispatcher->dispatch($this->request, $this->response); } $this->response->send(); $this->shutdown($runLevel); }
/** * Run the interactive Shell * * The shell command runs Flow's interactive shell. This shell allows for * entering commands like through the regular command line interface but * additionally supports autocompletion and a user-based command history. * * @return void */ public function shellCommand() { if (!function_exists('readline_read_history')) { $this->outputLine('Interactive Shell is not available on this system!'); $this->quit(1); } $subProcess = false; $pipes = array(); $historyPathAndFilename = getenv('HOME') . '/.flow_' . md5(FLOW_PATH_ROOT); readline_read_history($historyPathAndFilename); readline_completion_function(array($this, 'autocomplete')); echo "Flow Interactive Shell\n\n"; while (true) { $commandLine = readline('Flow > '); if ($commandLine == '') { echo "\n"; break; } readline_add_history($commandLine); readline_write_history($historyPathAndFilename); $request = $this->requestBuilder->build($commandLine); $response = new Response(); $command = $request->getCommand(); if ($request === false || $command->getCommandIdentifier() === false) { echo "Bad command\n"; continue; } if ($this->bootstrap->isCompiletimeCommand($command->getCommandIdentifier())) { $this->dispatcher->dispatch($request, $response); $response->send(); if (is_resource($subProcess)) { $this->quitSubProcess($subProcess, $pipes); } } else { if (is_resource($subProcess)) { $subProcessStatus = proc_get_status($subProcess); if ($subProcessStatus['running'] === false) { proc_close($subProcess); } } if (!is_resource($subProcess)) { list($subProcess, $pipes) = $this->launchSubProcess(); if ($subProcess === false || !is_array($pipes)) { echo "Failed launching the shell sub process for executing the runtime command.\n"; continue; } $this->echoSubProcessResponse($pipes); } fwrite($pipes[0], $commandLine . "\n"); fflush($pipes[0]); $this->echoSubProcessResponse($pipes); if ($command->isFlushingCaches()) { $this->quitSubProcess($subProcess, $pipes); } } } if (is_resource($subProcess)) { $this->quitSubProcess($subProcess, $pipes); } echo "Bye!\n"; }
/** * @test * @expectedException \TYPO3\Flow\Security\Exception\AccessDeniedException */ public function dispatchRethrowsAccessDeniedException() { $this->mockActionRequest->expects($this->any())->method('isDispatched')->will($this->returnValue(TRUE)); $this->mockFirewall->expects($this->once())->method('blockIllegalRequests')->will($this->throwException(new AccessDeniedException())); $this->dispatcher->dispatch($this->mockActionRequest, $this->mockHttpResponse); }