/** * Determines the action method and assures that the method exists. * * @return string The action method name * @throws NoSuchActionException if the action specified in the request object does not exist (and if there's no default action either). */ protected function resolveActionMethodName() { if ($this->request->hasArgument('resource') === false) { $this->throwStatus(400); } $this->endpoint = new EndpointService($this->request->getArgument('resource')); if ($this->request->getControllerActionName() === 'index') { $actionName = 'index'; switch ($this->request->getHttpRequest()->getMethod()) { case 'HEAD': case 'GET': if ($this->request->hasArgument('resource') && $this->request->hasArgument('identifier')) { $actionName = 'show'; } else { $actionName = 'index'; } break; case 'POST': case 'PUT': case 'DELETE': throw new NoSuchActionException('Not implemented currently', 1447800455); break; } $this->request->setControllerActionName($actionName); } return parent::resolveActionMethodName(); }
public function __construct() { parent::__construct(); $this->dumpDirectory = FLOW_PATH_DATA . 'Persistent/GermaniaSacra/Dump/'; if (!file_exists($this->dumpDirectory)) { Files::createDirectoryRecursively($this->dumpDirectory); } }
/** * @param \TYPO3\Flow\Mvc\View\ViewInterface $view The view to be initialized * @return void */ protected function initializeView(\TYPO3\Flow\Mvc\View\ViewInterface $view) { parent::initializeView($view); $detector = new \TYPO3\Flow\I18n\Detector(); $locale = $detector->detectLocaleFromHttpHeader($_SERVER["HTTP_ACCEPT_LANGUAGE"]); $view->assign('locale', $locale); $view->assign('session', $this->session); }
/** * Handles a request. The result output is returned by altering the given response. * * @param \TYPO3\Flow\Mvc\ActionRequest $request The request object * @param \TYPO3\Flow\Http\Response $response The response, modified by this handler * @return void * @throws \TYPO3\Fluid\Core\Widget\Exception\WidgetContextNotFoundException * @api */ public function processRequest(\TYPO3\Flow\Mvc\RequestInterface $request, \TYPO3\Flow\Mvc\ResponseInterface $response) { $widgetContext = $request->getInternalArgument('__widgetContext'); if ($widgetContext === NULL) { throw new \TYPO3\Fluid\Core\Widget\Exception\WidgetContextNotFoundException('The widget context could not be found in the request.', 1307450180); } $this->widgetConfiguration = $widgetContext->getWidgetConfiguration(); parent::processRequest($request, $response); }
/** * @return \TYPO3\Flow\Error\Message */ protected function getErrorFlashMessage() { #\TYPO3\Flow\var_dump($this->request->getArguments()); switch ($this->actionMethodName) { case 'createAction': return new \TYPO3\Flow\Error\Message('Could not save form, because some fields are not filled out correctly'); default: return parent::getErrorFlashMessage(); } }
/** * Handles a request. The result output is returned by altering the given response. * * @param RequestInterface $request The request object * @param ResponseInterface $response The response, modified by this handler * @return void * @throws WidgetContextNotFoundException * @api */ public function processRequest(RequestInterface $request, ResponseInterface $response) { /** @var $request \TYPO3\Flow\Mvc\ActionRequest */ /** @var $widgetContext WidgetContext */ $widgetContext = $request->getInternalArgument('__widgetContext'); if ($widgetContext === NULL) { throw new WidgetContextNotFoundException('The widget context could not be found in the request.', 1307450180); } $this->widgetConfiguration = $widgetContext->getWidgetConfiguration(); parent::processRequest($request, $response); }
/** * Resolve view object. Falls back to TYPO3.Ice package templates * if current package does not contain a template for current request. * * @return \TYPO3\Flow\Mvc\View\ViewInterface the resolved view */ public function resolveView() { $view = parent::resolveView(); if (!$view->canRender($this->controllerContext) && $this->request->getFormat() === 'html') { $templateFileName = \TYPO3\Flow\Utility\Files::concatenatePaths(array($this->packageManager->getPackage('TYPO3.Ice')->getPackagePath(), 'Resources', 'Private', 'Templates', 'Standard', 'Index.html')); // Fallback to TYPO3.Ice template if file exists if (file_exists($templateFileName)) { $view->setTemplatePathAndFilename($templateFileName); } } return $view; }
/** * Catch exceptions while processing an exception and respond to JSON format * TODO: This is an explicit exception handling that will be replaced by format-enabled exception handlers. * * @param RequestInterface $request The request object * @param ResponseInterface $response The response, modified by this handler * @return void * @throws \Exception */ public function processRequest(RequestInterface $request, ResponseInterface $response) { try { parent::processRequest($request, $response); } catch (StopActionException $exception) { throw $exception; } catch (\Exception $exception) { if ($this->request->getFormat() !== 'json' || !$response instanceof HttpResponse) { throw $exception; } $exceptionData = $this->convertException($exception); $response->setHeader('Content-Type', 'application/json'); if ($exception instanceof FlowException) { $response->setStatus($exception->getStatusCode()); } else { $response->setStatus(500); } $response->setContent(json_encode(array('error' => $exceptionData))); $this->systemLogger->logException($exception); } }
/** * @test * @dataProvider ignoredValidationArgumentsProvider */ public function initializeActionMethodValidatorsDoesNotAddValidatorForIgnoredArgumentsWithoutEvaluation($evaluateIgnoredValidationArgument, $setValidatorShouldBeCalled) { $this->actionController = $this->getAccessibleMock(\TYPO3\Flow\Mvc\Controller\ActionController::class, array('getInformationNeededForInitializeActionMethodValidators')); $mockArgument = $this->getMockBuilder(\TYPO3\Flow\Mvc\Controller\Argument::class)->disableOriginalConstructor()->getMock(); $mockArgument->expects($this->any())->method('getName')->will($this->returnValue('node')); $arguments = new Arguments(); $arguments['node'] = $mockArgument; $ignoredValidationArguments = array('showAction' => array('node' => array('evaluate' => $evaluateIgnoredValidationArgument))); $mockValidator = $this->createMock(\TYPO3\Flow\Validation\Validator\ValidatorInterface::class); $parameterValidators = array('node' => $mockValidator); $this->actionController->expects($this->any())->method('getInformationNeededForInitializeActionMethodValidators')->will($this->returnValue(array(array(), array(), array(), $ignoredValidationArguments))); $this->inject($this->actionController, 'actionMethodName', 'showAction'); $this->inject($this->actionController, 'arguments', $arguments); $this->inject($this->actionController, 'objectManager', $this->mockObjectManager); $mockValidatorResolver = $this->createMock(\TYPO3\Flow\Validation\ValidatorResolver::class); $mockValidatorResolver->expects($this->any())->method('buildMethodArgumentsValidatorConjunctions')->will($this->returnValue($parameterValidators)); $this->inject($this->actionController, 'validatorResolver', $mockValidatorResolver); if ($setValidatorShouldBeCalled) { $mockArgument->expects($this->once())->method('setValidator'); } else { $mockArgument->expects($this->never())->method('setValidator'); } $this->actionController->_call('initializeActionMethodValidators'); }
/** * Add a translated flashMessage. * * @param string $messageBody The translation id for the message body. * @param string $messageTitle The translation id for the message title. * @param string $severity * @param array $messageArguments * @param integer $messageCode * @return void */ public function addFlashMessage($messageBody, $messageTitle = '', $severity = Message::SEVERITY_OK, array $messageArguments = array(), $messageCode = null) { if (is_string($messageBody)) { $messageBody = $this->translator->translateById($messageBody, $messageArguments, null, null, 'Main', 'TYPO3.Media') ?: $messageBody; } $messageTitle = $this->translator->translateById($messageTitle, $messageArguments, null, null, 'Main', 'TYPO3.Media'); parent::addFlashMessage($messageBody, $messageTitle, $severity, $messageArguments, $messageCode); }
public function __construct($logger = null) { parent::__construct(); $this->logger = $logger; }
/** * @param ViewInterface $view * @return void */ protected function initializeView(ViewInterface $view) { /** @var TemplateView $view */ $view->setOption('templateRootPathPattern', '@packageResourcesPath/Private/'); parent::initializeView($view); }
protected function throwStatus($statusCode, $statusMessage = null, $content = null) { if ($statusCode !== 406) { parent::throwStatus($statusCode, $statusMessage, $content); } }
/** * Catch Google service exceptions and forward to the "apiError" action to show * an error message. * * @return void */ protected function callActionMethod() { try { parent::callActionMethod(); } catch (\Google_Service_Exception $exception) { $this->addFlashMessage('%1$s', 'Google API error', \TYPO3\Flow\Error\Message::SEVERITY_ERROR, array('message' => $exception->getMessage(), 1415797974)); $this->forward('errorMessage'); } catch (MissingConfigurationException $exception) { $this->addFlashMessage('%1$s', 'Missing configuration', \TYPO3\Flow\Error\Message::SEVERITY_ERROR, array('message' => $exception->getMessage(), 1415797974)); $this->forward('errorMessage'); } catch (AuthenticationRequiredException $exception) { $this->redirect('authenticate'); } }
/** * Set the controller context on the feedback collection after the controller * has been initialized * * @param RequestInterface $request * @param ResponseInterface $response * @return void */ public function initializeController(RequestInterface $request, ResponseInterface $response) { parent::initializeController($request, $response); $this->feedbackCollection->setControllerContext($this->getControllerContext()); }
/** * Redirects the web request to another uri. * * NOTE: This method only supports web requests and will throw an exception * if used with other request types. * * @param mixed $uri Either a string representation of a URI or a \TYPO3\Flow\Http\Uri object * @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" * @return void * @throws \TYPO3\Flow\Mvc\Exception\StopActionException * @api */ protected function redirectToUri($uri, $delay = 0, $statusCode = 303) { // the parent method throws the exception, but we need to act afterwards // thus the code in catch - it's the expected state try { parent::redirectToUri($uri, $delay, $statusCode); } catch (\TYPO3\Flow\Mvc\Exception\StopActionException $exception) { if ($this->request->getFormat() === 'json') { $this->response->setContent(''); } throw $exception; } }
/** * Override getErrorFlashMessage to present nice flash error messages. * * @return \TYPO3\Flow\Error\Message */ protected function getErrorFlashMessage() { switch ($this->actionMethodName) { case 'createAction': return new \TYPO3\Flow\Error\Error('Could not create the new comment'); default: return parent::getErrorFlashMessage(); } }