Esempio n. 1
0
 /**
  * @param array $module
  * @return void
  * @FLOW3\SkipCsrfProtection
  */
 public function indexAction(array $module)
 {
     $moduleRequest = new ActionRequest($this->request);
     $moduleRequest->setArgumentNamespace('moduleArguments');
     $moduleRequest->setControllerObjectName($module['controller']);
     $moduleRequest->setControllerActionName($module['action']);
     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 = \TYPO3\FLOW3\Utility\Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $modules));
     $moduleConfiguration['path'] = $module['module'];
     $moduleBreadcrumb = array();
     $path = array();
     foreach ($modules as $moduleIdentifier) {
         array_push($path, $moduleIdentifier);
         $config = \TYPO3\FLOW3\Utility\Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $path));
         $moduleBreadcrumb[implode('/', $path)] = $config['label'];
     }
     $moduleRequest->setArgument('__moduleConfiguration', $moduleConfiguration);
     $moduleRequest->setArgument('__moduleBreadcrumb', $moduleBreadcrumb);
     $moduleResponse = new Response($this->response);
     $this->dispatcher->dispatch($moduleRequest, $moduleResponse);
     $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));
 }
Esempio n. 2
0
 /**
  * Sends the given HTTP request
  *
  * @param \TYPO3\FLOW3\Http\Request $request
  * @return \TYPO3\FLOW3\Http\Response
  * @throws \TYPO3\FLOW3\Http\Exception
  * @api
  */
 public function sendRequest(Request $request)
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if (!$requestHandler instanceof \TYPO3\FLOW3\Tests\FunctionalTestRequestHandler) {
         throw new \TYPO3\FLOW3\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->injectRequest($actionRequest);
         $this->dispatcher->dispatch($actionRequest, $response);
     } 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 FLOW3 ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
         $content .= 'thrown in file ' . $filePathAndName . PHP_EOL;
         $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL;
         $content .= \TYPO3\FLOW3\Error\Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL;
         $response->setStatus(500);
         $response->setContent($content);
         $response->setHeader('X-FLOW3-ExceptionCode', $exceptionCodeNumber);
         $response->setHeader('X-FLOW3-ExceptionMessage', $exception->getMessage());
     }
     return $response;
 }
Esempio n. 3
0
 /**
  * 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->injectRequest($actionRequest);
     $this->dispatcher->dispatch($actionRequest, $this->response);
     $this->response->makeStandardsCompliant($this->request);
     $this->response->send();
     $this->bootstrap->shutdown('Runtime');
     $this->exit->__invoke();
 }
Esempio n. 4
0
 /**
  * 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\\FLOW3\\Cli\\CommandExceptionHandler');
     } catch (\Exception $exception) {
         \TYPO3\FLOW3\Cli\CommandExceptionHandler::writeResponseAndExit($exception);
     }
     $commandLine = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
     $this->request = $this->objectManager->get('TYPO3\\FLOW3\\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);
 }
Esempio n. 5
0
 /**
  * Run the interactive Shell
  *
  * The shell command runs FLOW3'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') . '/.flow3_' . md5(FLOW3_PATH_ROOT);
     readline_read_history($historyPathAndFilename);
     readline_completion_function(array($this, 'autocomplete'));
     echo "FLOW3 Interactive Shell\n\n";
     while (true) {
         $commandLine = readline('FLOW3 > ');
         if ($commandLine == '') {
             echo "\n";
             break;
         }
         readline_add_history($commandLine);
         readline_write_history($historyPathAndFilename);
         $request = $this->requestBuilder->build($commandLine);
         $response = new \TYPO3\FLOW3\Cli\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";
 }