/**
  * Sends the specified HTTP status immediately.
  *
  * NOTE: This method only supports web requests and will thrown an exception if used with other request types.
  *
  * @param integer $statusCode The HTTP status code
  * @param string $statusMessage A custom HTTP status message
  * @param string $content Body content which further explains the status
  * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException If the request is not a web request
  * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
  * @api
  */
 public function throwStatus($statusCode, $statusMessage = NULL, $content = NULL)
 {
     if (!$this->request instanceof \TYPO3\CMS\Extbase\Mvc\Web\Request) {
         throw new \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException('throwStatus() only supports web requests.', 1220539739);
     }
     $this->response->setStatus($statusCode, $statusMessage);
     if ($content === NULL) {
         $content = $this->response->getStatus();
     }
     $this->response->setContent($content);
     throw new \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException();
 }
Example #2
0
 /**
  * Sends additional headers and returns the content
  *
  * @return null|string
  */
 public function shutdown()
 {
     if (!empty($this->getAdditionalHeaderData())) {
         $this->getTypoScriptFrontendController()->additionalHeaderData[] = implode(LF, $this->getAdditionalHeaderData());
     }
     $this->sendHeaders();
     return parent::shutdown();
 }
Example #3
0
 /**
  * Sends additional headers and returns the content
  *
  * @return null|string
  */
 public function shutdown()
 {
     if (count($this->getAdditionalHeaderData()) > 0) {
         $this->getTypoScriptFrontendController()->additionalHeaderData[] = implode(chr(10), $this->getAdditionalHeaderData());
     }
     $this->sendHeaders();
     return parent::shutdown();
 }
Example #4
0
 /**
  * @test
  */
 public function __toStringReturnsActualContent()
 {
     $this->mockResponse->_set('content', 'foo');
     $this->assertSame('foo', (string) $this->mockResponse);
 }
Example #5
0
 /**
  * Calls the specified action method and passes the arguments.
  *
  * If the action returns a string, it is appended to the content in the
  * response object. If the action doesn't return anything and a valid
  * view exists, the view is rendered automatically.
  *
  * @return void
  * @api
  */
 protected function callActionMethod()
 {
     $preparedArguments = array();
     /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
     foreach ($this->arguments as $argument) {
         $preparedArguments[] = $argument->getValue();
     }
     $validationResult = $this->arguments->getValidationResults();
     if (!$validationResult->hasErrors()) {
         $this->emitBeforeCallActionMethodSignal($preparedArguments);
         $actionResult = call_user_func_array(array($this, $this->actionMethodName), $preparedArguments);
     } else {
         $methodTagsValues = $this->reflectionService->getMethodTagsValues(get_class($this), $this->actionMethodName);
         $ignoreValidationAnnotations = array();
         if (isset($methodTagsValues['ignorevalidation'])) {
             $ignoreValidationAnnotations = $methodTagsValues['ignorevalidation'];
         }
         // if there exists more errors than in ignoreValidationAnnotations_=> call error method
         // else => call action method
         $shouldCallActionMethod = TRUE;
         foreach ($validationResult->getSubResults() as $argumentName => $subValidationResult) {
             if (!$subValidationResult->hasErrors()) {
                 continue;
             }
             if (array_search('$' . $argumentName, $ignoreValidationAnnotations) !== FALSE) {
                 continue;
             }
             $shouldCallActionMethod = FALSE;
         }
         if ($shouldCallActionMethod) {
             $this->emitBeforeCallActionMethodSignal($preparedArguments);
             $actionResult = call_user_func_array(array($this, $this->actionMethodName), $preparedArguments);
         } else {
             $actionResult = call_user_func(array($this, $this->errorMethodName));
         }
     }
     if ($actionResult === NULL && $this->view instanceof ViewInterface) {
         $this->response->appendContent($this->view->render());
     } elseif (is_string($actionResult) && strlen($actionResult) > 0) {
         $this->response->appendContent($actionResult);
     } elseif (is_object($actionResult) && method_exists($actionResult, '__toString')) {
         $this->response->appendContent((string) $actionResult);
     }
 }
Example #6
0
 /**
  * Sends additional headers and returns the content
  *
  * @return null|string
  */
 public function shutdown()
 {
     if (count($this->getAdditionalHeaderData()) > 0) {
         $GLOBALS['TSFE']->additionalHeaderData[] = implode(chr(10), $this->getAdditionalHeaderData());
     }
     $this->sendHeaders();
     return parent::shutdown();
 }