本文整理汇总了PHP中TYPO3\CMS\Extbase\Reflection\ReflectionService::getMethodParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionService::getMethodParameters方法的具体用法?PHP ReflectionService::getMethodParameters怎么用?PHP ReflectionService::getMethodParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Extbase\Reflection\ReflectionService
的用法示例。
在下文中一共展示了ReflectionService::getMethodParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createApi
/**
* Creates the remote api based on the module/plugin configuration using the extbase
* reflection features.
*
* @param string $routeUrl
* @param string $namespace
* @return array
*/
public function createApi($routeUrl, $namespace)
{
$api = [];
$api['url'] = $routeUrl;
$api['type'] = 'remoting';
$api['namespace'] = $namespace;
$api['actions'] = [];
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 = 'Ecodev\\Newsletter\\Controller\\' . $unstrippedControllerName;
$controllerActions = [];
foreach ($allowedControllerActions['actions'] as $actionName) {
$unstrippedActionName = $actionName . 'Action';
try {
$actionParameters = $this->reflectionService->getMethodParameters($controllerObjectName, $unstrippedActionName);
$controllerActions[] = ['len' => count($actionParameters), 'name' => $unstrippedActionName];
} catch (ReflectionException $re) {
if ($unstrippedActionName !== 'extObjAction') {
\Ecodev\Newsletter\Tools::getLogger(__CLASS__)->critical('You have a not existing action (' . $controllerObjectName . '::' . $unstrippedActionName . ') in your module/plugin configuration. This action will not be available for Ext.Direct remote execution.');
}
}
}
$api['actions'][$unstrippedControllerName] = $controllerActions;
}
return $api;
}
示例2: parseRawCommandLineArguments
/**
* Takes an array of unparsed command line arguments and options and converts it separated
* by named arguments, options and unnamed arguments.
*
* @param array $rawCommandLineArguments The unparsed command parts (such as "--foo") as an array
* @param string $controllerObjectName Object name of the designated command controller
* @param string $controllerCommandName Command name of the recognized command (ie. method name without "Command" suffix)
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentMixingException
* @return array All and exceeding command line arguments
*/
protected function parseRawCommandLineArguments(array $rawCommandLineArguments, $controllerObjectName, $controllerCommandName) {
$commandLineArguments = array();
$exceedingArguments = array();
$commandMethodName = $controllerCommandName . 'Command';
$commandMethodParameters = $this->reflectionService->getMethodParameters($controllerObjectName, $commandMethodName);
$requiredArguments = array();
$optionalArguments = array();
$argumentNames = array();
foreach ($commandMethodParameters as $parameterName => $parameterInfo) {
$argumentNames[] = $parameterName;
if ($parameterInfo['optional'] === FALSE) {
$requiredArguments[strtolower($parameterName)] = array('parameterName' => $parameterName, 'type' => $parameterInfo['type']);
} else {
$optionalArguments[strtolower($parameterName)] = array('parameterName' => $parameterName, 'type' => $parameterInfo['type']);
}
}
$decidedToUseNamedArguments = FALSE;
$decidedToUseUnnamedArguments = FALSE;
$argumentIndex = 0;
while (count($rawCommandLineArguments) > 0) {
$rawArgument = array_shift($rawCommandLineArguments);
if ($rawArgument[0] === '-') {
if ($rawArgument[1] === '-') {
$rawArgument = substr($rawArgument, 2);
} else {
$rawArgument = substr($rawArgument, 1);
}
$argumentName = $this->extractArgumentNameFromCommandLinePart($rawArgument);
if (isset($optionalArguments[$argumentName])) {
$argumentValue = $this->getValueOfCurrentCommandLineOption($rawArgument, $rawCommandLineArguments, $optionalArguments[$argumentName]['type']);
$commandLineArguments[$optionalArguments[$argumentName]['parameterName']] = $argumentValue;
} elseif (isset($requiredArguments[$argumentName])) {
if ($decidedToUseUnnamedArguments) {
throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentMixingException(sprintf('Unexpected named argument "%s". If you use unnamed arguments, all required arguments must be passed without a name.', $argumentName), 1309971821);
}
$decidedToUseNamedArguments = TRUE;
$argumentValue = $this->getValueOfCurrentCommandLineOption($rawArgument, $rawCommandLineArguments, $requiredArguments[$argumentName]['type']);
$commandLineArguments[$requiredArguments[$argumentName]['parameterName']] = $argumentValue;
unset($requiredArguments[$argumentName]);
}
} else {
if (count($requiredArguments) > 0) {
if ($decidedToUseNamedArguments) {
throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentMixingException(sprintf('Unexpected unnamed argument "%s". If you use named arguments, all required arguments must be passed named.', $rawArgument), 1309971820);
}
$argument = array_shift($requiredArguments);
$commandLineArguments[$argument['parameterName']] = $rawArgument;
$decidedToUseUnnamedArguments = TRUE;
} else {
if ($argumentIndex < count($argumentNames)) {
$commandLineArguments[$argumentNames[$argumentIndex]] = $rawArgument;
} else {
$exceedingArguments[] = $rawArgument;
}
}
}
$argumentIndex++;
}
return array($commandLineArguments, $exceedingArguments);
}
示例3: registerRenderMethodArguments
/**
* Register method arguments for "render" by analysing the doc comment above.
*
* @return void
* @throws \TYPO3Fluid\Fluid\Core\Parser\Exception
*/
protected function registerRenderMethodArguments()
{
$methodParameters = $this->reflectionService->getMethodParameters(get_class($this), 'render');
if (count($methodParameters) === 0) {
return;
}
$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 = isset($parameterInfo['array']) && (bool) $parameterInfo['array'] ? 'array' : $parameterInfo['type'];
} else {
throw new \TYPO3\CMS\Fluid\Core\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 (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 ArgumentDefinition($parameterName, $dataType, $description, $parameterInfo['optional'] === false, $defaultValue, true);
$i++;
}
}
示例4: getDefaultArgumentValue
/**
* Gets the default value of argument
*
* @param \TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition $argument
* @return mixed
*/
protected function getDefaultArgumentValue(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition $argument)
{
$type = $this->getArgumentType($argument);
$argumentName = $argument->getName();
$command = $this->commandManager->getCommandByIdentifier($this->task->getCommandIdentifier());
$argumentReflection = $this->reflectionService->getMethodParameters($command->getControllerClassName(), $command->getControllerCommandName() . 'Command');
$defaultValue = $argumentReflection[$argumentName]['defaultValue'];
if ($type === 'boolean') {
$defaultValue = (bool) $defaultValue ? 1 : 0;
}
return $defaultValue;
}
示例5: buildMethodArgumentsValidatorConjunctions
/**
* 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
*
* @param string $className
* @param string $methodName
* @param array $methodParameters Optional pre-compiled array of method parameters
* @param array $methodValidateAnnotations Optional pre-compiled array of validate annotations (as array)
* @return ConjunctionValidator[] An Array of ValidatorConjunctions for each method parameters.
* @throws \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationConfigurationException
* @throws \TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException
* @throws \TYPO3\CMS\Extbase\Validation\Exception\InvalidTypeHintException
*/
public function buildMethodArgumentsValidatorConjunctions($className, $methodName, array $methodParameters = NULL, array $methodValidateAnnotations = NULL)
{
/** @var ConjunctionValidator[] $validatorConjunctions */
$validatorConjunctions = array();
if ($methodParameters === NULL) {
$methodParameters = $this->reflectionService->getMethodParameters($className, $methodName);
}
if (count($methodParameters) === 0) {
return $validatorConjunctions;
}
foreach ($methodParameters as $parameterName => $methodParameter) {
/** @var ConjunctionValidator $validatorConjunction */
$validatorConjunction = $this->createValidator('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator');
if (!array_key_exists('type', $methodParameter)) {
throw new Exception\InvalidTypeHintException('Missing type information, probably no @param annotation for parameter "$' . $parameterName . '" in ' . $className . '->' . $methodName . '()', 1281962564);
}
// @todo: remove check for old underscore model name syntax once it's possible
if (strpbrk($methodParameter['type'], '_\\') === FALSE) {
$typeValidator = $this->createValidator($methodParameter['type']);
} elseif (preg_match('/[\\_]Model[\\_]/', $methodParameter['type']) !== FALSE) {
$possibleValidatorClassName = str_replace(array('\\Model\\', '_Model_'), array('\\Validator\\', '_Validator_'), $methodParameter['type']) . 'Validator';
$typeValidator = $this->createValidator($possibleValidatorClassName);
} else {
$typeValidator = NULL;
}
if ($typeValidator !== NULL) {
$validatorConjunction->addValidator($typeValidator);
}
$validatorConjunctions[$parameterName] = $validatorConjunction;
}
if ($methodValidateAnnotations === NULL) {
$validateAnnotations = $this->getMethodValidateAnnotations($className, $methodName);
$methodValidateAnnotations = array_map(function ($validateAnnotation) {
return array('type' => $validateAnnotation['validatorName'], 'options' => $validateAnnotation['validatorOptions'], 'argumentName' => $validateAnnotation['argumentName']);
}, $validateAnnotations);
}
foreach ($methodValidateAnnotations as $annotationParameters) {
$newValidator = $this->createValidator($annotationParameters['type'], $annotationParameters['options']);
if ($newValidator === NULL) {
throw new Exception\NoSuchValidatorException('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Could not resolve class name for validator "' . $annotationParameters['type'] . '".', 1239853109);
}
if (isset($validatorConjunctions[$annotationParameters['argumentName']])) {
$validatorConjunctions[$annotationParameters['argumentName']]->addValidator($newValidator);
} elseif (strpos($annotationParameters['argumentName'], '.') !== FALSE) {
$objectPath = explode('.', $annotationParameters['argumentName']);
$argumentName = array_shift($objectPath);
$validatorConjunctions[$argumentName]->addValidator($this->buildSubObjectValidator($objectPath, $newValidator));
} else {
throw new Exception\InvalidValidationConfigurationException('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Validator specified for argument name "' . $annotationParameters['argumentName'] . '", but this argument does not exist.', 1253172726);
}
}
return $validatorConjunctions;
}
示例6: buildMethodArgumentsValidatorConjunctions
/**
* 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
*
* @param string $className
* @param string $methodName
* @param array $methodParameters Optional pre-compiled array of method parameters
* @param array $methodValidateAnnotations Optional pre-compiled array of validate annotations (as array)
* @return ConjunctionValidator[] An Array of ValidatorConjunctions for each method parameters.
* @throws \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationConfigurationException
* @throws \TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException
* @throws \TYPO3\CMS\Extbase\Validation\Exception\InvalidTypeHintException
*/
public function buildMethodArgumentsValidatorConjunctions($className, $methodName, array $methodParameters = null, array $methodValidateAnnotations = null)
{
/** @var ConjunctionValidator[] $validatorConjunctions */
$validatorConjunctions = [];
if ($methodParameters === null) {
$methodParameters = $this->reflectionService->getMethodParameters($className, $methodName);
}
if (empty($methodParameters)) {
return $validatorConjunctions;
}
foreach ($methodParameters as $parameterName => $methodParameter) {
/** @var ConjunctionValidator $validatorConjunction */
$validatorConjunction = $this->createValidator(ConjunctionValidator::class);
if (!array_key_exists('type', $methodParameter)) {
throw new Exception\InvalidTypeHintException('Missing type information, probably no @param annotation for parameter "$' . $parameterName . '" in ' . $className . '->' . $methodName . '()', 1281962564);
}
// @todo: remove check for old underscore model name syntax once it's possible
if (strpbrk($methodParameter['type'], '_\\') === false) {
$typeValidator = $this->createValidator($methodParameter['type']);
} else {
$typeValidator = null;
}
if ($typeValidator !== null) {
$validatorConjunction->addValidator($typeValidator);
}
$validatorConjunctions[$parameterName] = $validatorConjunction;
}
if ($methodValidateAnnotations === null) {
$validateAnnotations = $this->getMethodValidateAnnotations($className, $methodName);
$methodValidateAnnotations = array_map(function ($validateAnnotation) {
return ['type' => $validateAnnotation['validatorName'], 'options' => $validateAnnotation['validatorOptions'], 'argumentName' => $validateAnnotation['argumentName']];
}, $validateAnnotations);
}
foreach ($methodValidateAnnotations as $annotationParameters) {
$newValidator = $this->createValidator($annotationParameters['type'], $annotationParameters['options']);
if ($newValidator === null) {
throw new Exception\NoSuchValidatorException('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Could not resolve class name for validator "' . $annotationParameters['type'] . '".', 1239853109);
}
if (isset($validatorConjunctions[$annotationParameters['argumentName']])) {
$validatorConjunctions[$annotationParameters['argumentName']]->addValidator($newValidator);
} elseif (strpos($annotationParameters['argumentName'], '.') !== false) {
$objectPath = explode('.', $annotationParameters['argumentName']);
$argumentName = array_shift($objectPath);
$validatorConjunctions[$argumentName]->addValidator($this->buildSubObjectValidator($objectPath, $newValidator));
} else {
throw new Exception\InvalidValidationConfigurationException('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Validator specified for argument name "' . $annotationParameters['argumentName'] . '", but this argument does not exist.', 1253172726);
}
}
return $validatorConjunctions;
}
示例7: initializeCommandMethodArguments
/**
* Initializes the arguments array of this controller by creating an empty argument object for each of the
* method arguments found in the designated command method.
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException
* @return void
*/
protected function initializeCommandMethodArguments()
{
$methodParameters = $this->reflectionService->getMethodParameters(get_class($this), $this->commandMethodName);
foreach ($methodParameters as $parameterName => $parameterInfo) {
$dataType = NULL;
if (isset($parameterInfo['type'])) {
$dataType = $parameterInfo['type'];
} elseif ($parameterInfo['array']) {
$dataType = 'array';
}
if ($dataType === NULL) {
throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException('The argument type for parameter $' . $parameterName . ' of method ' . get_class($this) . '->' . $this->commandMethodName . '() could not be detected.', 1306755296);
}
$defaultValue = isset($parameterInfo['defaultValue']) ? $parameterInfo['defaultValue'] : NULL;
$this->arguments->addNewArgument($parameterName, $dataType, $parameterInfo['optional'] === FALSE, $defaultValue);
}
}
示例8: initializeCommandMethodArguments
/**
* Initializes the arguments array of this controller by creating an empty argument object for each of the
* method arguments found in the designated command method.
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException
* @return void
* @throws InvalidArgumentTypeException
*/
protected function initializeCommandMethodArguments()
{
$methodParameters = $this->reflectionService->getMethodParameters(get_class($this), $this->commandMethodName);
foreach ($methodParameters as $parameterName => $parameterInfo) {
$dataType = null;
if (isset($parameterInfo['type'])) {
$dataType = $parameterInfo['type'];
} elseif ($parameterInfo['array']) {
$dataType = 'array';
}
if ($dataType === null) {
throw new InvalidArgumentTypeException(sprintf('The argument type for parameter $%s of method %s->%s() could not be detected.', $parameterName, get_class($this), $this->commandMethodName), 1306755296);
}
$defaultValue = isset($parameterInfo['defaultValue']) ? $parameterInfo['defaultValue'] : null;
$this->arguments->addNewArgument($parameterName, $dataType, $parameterInfo['optional'] === false, $defaultValue);
}
}
示例9: getArgumentDefinitions
/**
* Returns an array of \TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition that contains
* information about required/optional arguments of this command.
* If the command does not expect any arguments, an empty array is returned
*
* @return array<\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition>
*/
public function getArgumentDefinitions()
{
if (!$this->hasArguments()) {
return array();
}
$commandArgumentDefinitions = array();
$commandMethodReflection = $this->getCommandMethodReflection();
$annotations = $commandMethodReflection->getTagsValues();
$commandParameters = $this->reflectionService->getMethodParameters($this->controllerClassName, $this->controllerCommandName . 'Command');
$i = 0;
foreach ($commandParameters as $commandParameterName => $commandParameterDefinition) {
$explodedAnnotation = preg_split('/\\s+/', $annotations['param'][$i], 3);
$description = !empty($explodedAnnotation[2]) ? $explodedAnnotation[2] : '';
$required = $commandParameterDefinition['optional'] !== TRUE;
$commandArgumentDefinitions[] = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, $commandParameterName, $required, $description);
$i++;
}
return $commandArgumentDefinitions;
}
示例10: getCommandMethodArguments
/**
* Initializes the arguments array of this controller by creating an empty argument object for each of the
* method arguments found in the designated command method.
*
* @param string $commandMethodName
* @return Arguments
* @throws InvalidArgumentTypeException
*/
protected function getCommandMethodArguments($commandMethodName)
{
$arguments = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Arguments');
$methodParameters = $this->reflectionService->getMethodParameters(self::INSTALL_COMMAND_CONTROLLER_CLASS, $commandMethodName);
foreach ($methodParameters as $parameterName => $parameterInfo) {
$dataType = NULL;
if (isset($parameterInfo['type'])) {
$dataType = $parameterInfo['type'];
} elseif ($parameterInfo['array']) {
$dataType = 'array';
}
if ($dataType === NULL) {
throw new InvalidArgumentTypeException(sprintf('The argument type for parameter $%s of method %s->%s() could not be detected.', $parameterName, self::INSTALL_COMMAND_CONTROLLER_CLASS, $commandMethodName), 1306755296);
}
$defaultValue = isset($parameterInfo['defaultValue']) ? $parameterInfo['defaultValue'] : NULL;
$arguments->addNewArgument($parameterName, $dataType, $parameterInfo['optional'] === FALSE, $defaultValue);
}
return $arguments;
}
示例11: getArguments
/**
* 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 <robert@typo3.org>
* @author Christopher Hlubek <hlubek@networkteam.com>
*/
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;
}
示例12: buildObject
/**
* Builds a new instance of $objectType with the given $possibleConstructorArgumentValues. If
* constructor argument values are missing from the given array the method
* looks for a default value in the constructor signature. Furthermore, the constructor arguments are removed from $possibleConstructorArgumentValues
*
* @param array &$possibleConstructorArgumentValues
* @param string $objectType
* @return object The created instance
* @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException if a required constructor argument is missing
*/
protected function buildObject(array &$possibleConstructorArgumentValues, $objectType) {
$specificObjectType = $this->objectContainer->getImplementationClassName($objectType);
if ($this->reflectionService->hasMethod($specificObjectType, '__construct')) {
$constructorSignature = $this->reflectionService->getMethodParameters($specificObjectType, '__construct');
$constructorArguments = array();
foreach ($constructorSignature as $constructorArgumentName => $constructorArgumentInformation) {
if (array_key_exists($constructorArgumentName, $possibleConstructorArgumentValues)) {
$constructorArguments[] = $possibleConstructorArgumentValues[$constructorArgumentName];
unset($possibleConstructorArgumentValues[$constructorArgumentName]);
} elseif ($constructorArgumentInformation['optional'] === TRUE) {
$constructorArguments[] = $constructorArgumentInformation['defaultValue'];
} else {
throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Missing constructor argument "' . $constructorArgumentName . '" for object of type "' . $objectType . '".', 1268734872);
}
}
return call_user_func_array(array($this->objectManager, 'get'), array_merge(array($objectType), $constructorArguments));
} else {
return $this->objectManager->get($objectType);
}
}
示例13: getArgumentDefinitions
/**
* Returns an array of \TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition that contains
* information about required/optional arguments of this command.
* If the command does not expect any arguments, an empty array is returned
*
* @return array<\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition>
*/
public function getArgumentDefinitions()
{
if (!$this->hasArguments()) {
return array();
}
$commandArgumentDefinitions = array();
$commandMethodReflection = $this->getCommandMethodReflection();
$annotations = $commandMethodReflection->getTagsValues();
$commandParameters = $this->reflectionService->getMethodParameters($this->controllerClassName, $this->controllerCommandName . 'Command');
$i = 0;
foreach ($commandParameters as $commandParameterName => $commandParameterDefinition) {
$explodedAnnotation = explode(' ', $annotations['param'][$i]);
array_shift($explodedAnnotation);
array_shift($explodedAnnotation);
$description = ltrim(implode(' ', $explodedAnnotation));
$required = $commandParameterDefinition['optional'] !== TRUE;
$commandArgumentDefinitions[] = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Cli\\CommandArgumentDefinition', $commandParameterName, $required, $description);
$i++;
}
return $commandArgumentDefinitions;
}
示例14: buildObject
/**
* Builds a new instance of $objectType with the given $possibleConstructorArgumentValues.
* If constructor argument values are missing from the given array the method looks for a
* default value in the constructor signature.
*
* Furthermore, the constructor arguments are removed from $possibleConstructorArgumentValues
*
* @param array &$possibleConstructorArgumentValues
* @param string $objectType
* @return object The created instance
* @throws \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException if a required constructor argument is missing
*/
protected function buildObject(array &$possibleConstructorArgumentValues, $objectType)
{
$className = $objectType;
if (method_exists($className, '__construct')) {
$constructorSignature = $this->reflectionService->getMethodParameters($className, '__construct');
$constructorArguments = array();
foreach ($constructorSignature as $constructorArgumentName => $constructorArgumentInformation) {
if (array_key_exists($constructorArgumentName, $possibleConstructorArgumentValues)) {
$constructorArguments[] = $possibleConstructorArgumentValues[$constructorArgumentName];
unset($possibleConstructorArgumentValues[$constructorArgumentName]);
} elseif ($constructorArgumentInformation['optional'] === true) {
$constructorArguments[] = $constructorArgumentInformation['defaultValue'];
} else {
throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException('Missing constructor argument "' . $constructorArgumentName . '" for object of type "' . $objectType . '".', 1268734872);
}
}
$classReflection = new \ReflectionClass($className);
return $classReflection->newInstanceArgs($constructorArguments);
} else {
return new $className();
}
}
示例15: getMethodParametersWithShortTypeNames
/**
* @test
*/
public function getMethodParametersWithShortTypeNames()
{
$service = new ReflectionService();
$parameters = $service->getMethodParameters(get_class($this), 'fixtureMethodForMethodTagsValuesWithShortTypes');
$this->assertSame(array('dummy' => array('position' => 0, 'byReference' => FALSE, 'array' => FALSE, 'optional' => FALSE, 'allowsNull' => TRUE, 'class' => NULL, 'type' => 'boolean'), 'foo' => array('position' => 1, 'byReference' => FALSE, 'array' => FALSE, 'optional' => FALSE, 'allowsNull' => TRUE, 'class' => NULL, 'type' => 'integer')), $parameters);
}