/** * Detects and registers any validators for arguments: * - by the data type specified in the @param annotations * - additional validators specified in the @validate annotations of a method * * @return array An Array of ValidatorConjunctions for each method parameters. */ public function buildMethodArgumentsValidatorConjunctions($className, $methodName) { $validatorConjunctions = array(); $methodParameters = $this->reflectionService->getMethodParameters($className, $methodName); $methodTagsValues = $this->reflectionService->getMethodTagsValues($className, $methodName); if (!count($methodParameters)) { // early return in case no parameters were found. return $validatorConjunctions; } foreach ($methodParameters as $parameterName => $methodParameter) { $validatorConjunction = $this->createValidator('Conjunction'); $typeValidator = $this->createValidator($methodParameter['type']); if ($typeValidator !== NULL) { $validatorConjunction->addValidator($typeValidator); } $validatorConjunctions[$parameterName] = $validatorConjunction; } if (isset($methodTagsValues['validate'])) { foreach ($methodTagsValues['validate'] as $validateValue) { $parsedAnnotation = $this->parseValidatorAnnotation($validateValue); foreach ($parsedAnnotation['validators'] as $validatorConfiguration) { $newValidator = $this->createValidator($validatorConfiguration['validatorName'], $validatorConfiguration['validatorOptions']); if ($newValidator === NULL) { throw new Tx_Extbase_Validation_Exception_NoSuchValidator('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Could not resolve class name for validator "' . $validatorConfiguration['validatorName'] . '".', 1239853109); } if (isset($validatorConjunctions[$parsedAnnotation['argumentName']])) { $validatorConjunctions[$parsedAnnotation['argumentName']]->addValidator($newValidator); } else { throw new Tx_Extbase_Validation_Exception_InvalidValidationConfiguration('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Validator specified for argument name "' . $parsedAnnotation['argumentName'] . '", but this argument does not exist.', 1253172726); } } } } return $validatorConjunctions; }
/** * Register method arguments for "render" by analysing the doc comment above. * * @return void * @author Sebastian Kurfürst <*****@*****.**> * @author Bastian Waidelich <*****@*****.**> */ private function registerRenderMethodArguments() { $methodParameters = $this->reflectionService->getMethodParameters(get_class($this), 'render'); if (count($methodParameters) === 0) { return; } if (Tx_Fluid_Fluid::$debugMode) { $methodTags = $this->reflectionService->getMethodTagsValues(get_class($this), 'render'); $paramAnnotations = array(); if (isset($methodTags['param'])) { $paramAnnotations = $methodTags['param']; } } $i = 0; foreach ($methodParameters as $parameterName => $parameterInfo) { $dataType = NULL; if (isset($parameterInfo['type'])) { $dataType = $parameterInfo['type']; } elseif ($parameterInfo['array']) { $dataType = 'array'; } if ($dataType === NULL) { throw new Tx_Fluid_Core_Parser_Exception('could not determine type of argument "' . $parameterName . '" of the render-method in ViewHelper "' . get_class($this) . '". Either the methods docComment is invalid or some PHP optimizer strips off comments.', 1242292003); } $description = ''; if (Tx_Fluid_Fluid::$debugMode && isset($paramAnnotations[$i])) { $explodedAnnotation = explode(' ', $paramAnnotations[$i]); array_shift($explodedAnnotation); array_shift($explodedAnnotation); $description = implode(' ', $explodedAnnotation); } $defaultValue = NULL; if (isset($parameterInfo['defaultValue'])) { $defaultValue = $parameterInfo['defaultValue']; } $this->argumentDefinitions[$parameterName] = new Tx_Fluid_Core_ViewHelper_ArgumentDefinition($parameterName, $dataType, $description, $parameterInfo['optional'] === FALSE, $defaultValue, TRUE); $i++; } }
/** * Checks the request hash (HMAC), if arguments have been touched by the property mapper. * * In case the @dontverifyrequesthash-Annotation has been set, this suppresses the exception. * * @return void * @throws Tx_Extbase_MVC_Exception_InvalidOrNoRequestHash In case request hash checking failed * @author Sebastian Kurfürst <*****@*****.**> */ protected function checkRequestHash() { if (!$this->request instanceof Tx_Extbase_MVC_Web_Request) { return; } // We only want to check it for now for web requests. if ($this->request->isHmacVerified()) { return; } // all good $verificationNeeded = FALSE; foreach ($this->arguments as $argument) { if ($argument->getOrigin() == Tx_Extbase_MVC_Controller_Argument::ORIGIN_NEWLY_CREATED || $argument->getOrigin() == Tx_Extbase_MVC_Controller_Argument::ORIGIN_PERSISTENCE_AND_MODIFIED) { $verificationNeeded = TRUE; } } if ($verificationNeeded) { $methodTagsValues = $this->reflectionService->getMethodTagsValues(get_class($this), $this->actionMethodName); if (!isset($methodTagsValues['dontverifyrequesthash'])) { throw new Tx_Extbase_MVC_Exception_InvalidOrNoRequestHash('Request hash (HMAC) checking failed. The parameter __hmac was invalid or not set, and objects were modified.', 1255082824); } } }
/** * @test */ public function getMethodTagsValues() { $service = new Tx_Extbase_Reflection_Service(); $tagsValues = $service->getMethodTagsValues('Tx_Extbase_Tests_Unit_Reflection_ServiceTest', 'fixtureMethodForMethodTagsValues'); $this->assertEquals(array('param' => array('array $foo The foo parameter'), 'return' => array('nothing')), $tagsValues); }