/** * 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; }
/** * Creates the remote api based on the module/plugin configuration using the extbase * reflection features. * * @param string $routeUrl * @param string $namespace * @return array */ protected function createApi($routeUrl, $namespace) { $api = array(); $api['url'] = $routeUrl; $api['type'] = 'remoting'; $api['namespace'] = $namespace; $api['actions'] = array(); if (empty($this->frameworkConfiguration['controllerConfiguration'])) { # @todo improve me! Hack for fetching API of newsletter the hard way! # It looks $this->frameworkConfiguration['controllerConfiguration'] is empty as of TYPO3 6.1. Bug or feature? $this->frameworkConfiguration['controllerConfiguration'] = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['Newsletter']['modules']['web_NewsletterTxNewsletterM1']['controllers']; } foreach ($this->frameworkConfiguration['controllerConfiguration'] as $controllerName => $allowedControllerActions) { $unstrippedControllerName = $controllerName . 'Controller'; $controllerObjectName = 'Tx_' . $this->frameworkConfiguration['extensionName'] . '_Controller_' . $unstrippedControllerName; $controllerActions = array(); foreach ($allowedControllerActions['actions'] as $actionName) { $unstrippedActionName = $actionName . 'Action'; try { $actionParameters = $this->reflectionService->getMethodParameters($controllerObjectName, $unstrippedActionName); $controllerActions[] = array('len' => count($actionParameters), 'name' => $unstrippedActionName); } catch (ReflectionException $re) { if ($unstrippedActionName !== 'extObjAction') { \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('You have a not existing action (' . $controllerObjectName . '::' . $unstrippedActionName . ') in your module/plugin configuration. This action will not be available for Ext.Direct remote execution.', 'Newsletter', 1); } } } $api['actions'][$unstrippedControllerName] = $controllerActions; } return $api; }
/** * Implementation of the arguments initilization in the action controller: * Automatically registers arguments of the current action * * Don't override this method - use initializeAction() instead. * * @return void * @see initializeArguments() */ protected function initializeActionMethodArguments() { $methodParameters = $this->reflectionService->getMethodParameters(get_class($this), $this->actionMethodName); 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_Extbase_MVC_Exception_InvalidArgumentType('The argument type for parameter "' . $parameterName . '" could not be detected.', 1253175643); } $defaultValue = isset($parameterInfo['defaultValue']) ? $parameterInfo['defaultValue'] : NULL; $this->arguments->addNewArgument($parameterName, $dataType, $parameterInfo['optional'] === FALSE, $defaultValue); } }
/** * Ext Direct does not provide named arguments by now, so we have * to map them by reflecting on the action parameters. * * @return array The mapped arguments * @author Robert Lemke <*****@*****.**> * @author Christopher Hlubek <*****@*****.**> */ public function getArguments() { if ($this->data === array()) { return array(); } $arguments = array(); if (!$this->request->isFormPost()) { $parameters = $this->reflectionService->getMethodParameters($this->getControllerObjectName(), $this->getControllerActionName() . 'Action'); // TODO Add checks for parameters foreach ($parameters as $name => $options) { $parameterIndex = $options['position']; if (isset($this->data[$parameterIndex])) { $arguments[$name] = $this->convertObjectToArray($this->data[$parameterIndex]); } } } else { // TODO Reuse setArgumentsFromRawRequestData from Web/RequestBuilder } return $arguments; }
/** * 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++; } }
/** * @test */ public function getMethodParameters() { $service = new Tx_Extbase_Reflection_Service(); $parameters = $service->getMethodParameters('Tx_Extbase_Tests_Unit_Reflection_ServiceTest', 'fixtureMethodForMethodTagsValues'); $this->assertEquals(array('foo' => array('position' => 0, 'byReference' => FALSE, 'array' => TRUE, 'optional' => FALSE, 'allowsNull' => FALSE, 'class' => NULL, 'type' => 'array')), $parameters); }