当前位置: 首页>>代码示例>>PHP>>正文


PHP Reflection\ReflectionService类代码示例

本文整理汇总了PHP中TYPO3\CMS\Extbase\Reflection\ReflectionService的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionService类的具体用法?PHP ReflectionService怎么用?PHP ReflectionService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ReflectionService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: renderStatic

 /**
  * Default implementation for use in compiled templates
  *
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return mixed
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     if (self::$staticReflectionService === NULL) {
         $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
         self::$staticReflectionService = $objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
     }
     $property = $arguments['property'];
     $validatorName = isset($arguments['validatorName']) ? $arguments['validatorName'] : NULL;
     $object = isset($arguments['object']) ? $arguments['object'] : NULL;
     if (NULL === $object) {
         $object = self::getFormObject($renderingContext->getViewHelperVariableContainer());
     }
     $className = get_class($object);
     if (FALSE !== strpos($property, '.')) {
         $pathSegments = explode('.', $property);
         foreach ($pathSegments as $property) {
             if (TRUE === ctype_digit($property)) {
                 continue;
             }
             $annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'var');
             $possibleClassName = array_pop($annotations);
             if (FALSE !== strpos($possibleClassName, '<')) {
                 $className = array_pop(explode('<', trim($possibleClassName, '>')));
             } elseif (TRUE === class_exists($possibleClassName)) {
                 $className = $possibleClassName;
             }
         }
     }
     $annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'validate');
     $hasEvaluated = TRUE;
     if (0 < count($annotations) && (NULL === $validatorName || TRUE === in_array($validatorName, $annotations))) {
         return static::renderStaticThenChild($arguments, $hasEvaluated);
     }
     return static::renderStaticElseChild($arguments, $hasEvaluated);
 }
开发者ID:smichaelsen,项目名称:vhs,代码行数:43,代码来源:HasValidatorViewHelper.php

示例2: render

 /**
  * Render
  *
  * Renders the then-child if the property at $property of the
  * object at $object (or the associated form object if $object
  * is not specified) uses a certain @validate validator.
  *
  * @param string $property The property name, dotted path supported, to determine required
  * @param string $validatorName The class name of the Validator that indicates the property is required
  * @param DomainObjectInterface $object Optional object - if not specified, grabs the associated form object
  * @return string
  */
 public function render($property, $validatorName = NULL, DomainObjectInterface $object = NULL)
 {
     if (NULL === $object) {
         $object = $this->getFormObject();
     }
     $className = get_class($object);
     if (FALSE !== strpos($property, '.')) {
         $pathSegments = explode('.', $property);
         foreach ($pathSegments as $property) {
             if (TRUE === ctype_digit($property)) {
                 continue;
             }
             $annotations = $this->ownReflectionService->getPropertyTagValues($className, $property, 'var');
             $possibleClassName = array_pop($annotations);
             if (FALSE !== strpos($possibleClassName, '<')) {
                 $className = array_pop(explode('<', trim($possibleClassName, '>')));
             } elseif (TRUE === class_exists($possibleClassName)) {
                 $className = $possibleClassName;
             }
         }
     }
     $annotations = $this->ownReflectionService->getPropertyTagValues($className, $property, 'validate');
     if (0 < count($annotations) && (NULL === $validatorName || TRUE === in_array($validatorName, $annotations))) {
         return $this->renderThenChild();
     }
     return $this->renderElseChild();
 }
开发者ID:JostBaron,项目名称:vhs,代码行数:39,代码来源:HasValidatorViewHelper.php

示例3: evaluateCondition

 /**
  * @param array $arguments
  * @return boolean
  */
 protected static function evaluateCondition($arguments = null)
 {
     if (self::$staticReflectionService === null) {
         $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
         self::$staticReflectionService = $objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
     }
     $property = $arguments['property'];
     $validatorName = isset($arguments['validatorName']) ? $arguments['validatorName'] : null;
     $object = isset($arguments['object']) ? $arguments['object'] : null;
     if (null === $object) {
         $object = static::getFormObject($renderingContext->getViewHelperVariableContainer());
     }
     $className = get_class($object);
     if (false !== strpos($property, '.')) {
         $pathSegments = explode('.', $property);
         foreach ($pathSegments as $property) {
             if (true === ctype_digit($property)) {
                 continue;
             }
             $annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'var');
             $possibleClassName = array_pop($annotations);
             if (false !== strpos($possibleClassName, '<')) {
                 $className = array_pop(explode('<', trim($possibleClassName, '>')));
             } elseif (true === class_exists($possibleClassName)) {
                 $className = $possibleClassName;
             }
         }
     }
     $annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'validate');
     return count($annotations) && (!$validatorName || in_array($validatorName, $annotations));
 }
开发者ID:fluidtypo3,项目名称:vhs,代码行数:35,代码来源:HasValidatorViewHelper.php

示例4: getTypeOfChildPropertyShouldUseReflectionServiceToDetermineType

 /**
  * @test
  */
 public function getTypeOfChildPropertyShouldUseReflectionServiceToDetermineType()
 {
     $this->mockReflectionService->expects($this->any())->method('hasMethod')->with('TheTargetType', 'setThePropertyName')->will($this->returnValue(FALSE));
     $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with('TheTargetType', '__construct')->will($this->returnValue(array('thePropertyName' => array('type' => 'TheTypeOfSubObject', 'elementType' => NULL))));
     $configuration = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration();
     $configuration->setTypeConverterOptions('TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\ObjectConverter', array());
     $this->assertEquals('TheTypeOfSubObject', $this->converter->getTypeOfChildProperty('TheTargetType', 'thePropertyName', $configuration));
 }
开发者ID:Mr-Robota,项目名称:TYPO3.CMS,代码行数:11,代码来源:ObjectConverterTest.php

示例5: booleanOptionsCanHaveOnlyCertainValuesIfTheValueIsAssignedWithoutEqualSign

 /**
  * @test
  * @author Robert Lemke <robert@typo3.org>
  */
 public function booleanOptionsCanHaveOnlyCertainValuesIfTheValueIsAssignedWithoutEqualSign()
 {
     $methodParameters = array('b1' => array('optional' => TRUE, 'type' => 'boolean'), 'b2' => array('optional' => TRUE, 'type' => 'boolean'), 'b3' => array('optional' => TRUE, 'type' => 'boolean'), 'b4' => array('optional' => TRUE, 'type' => 'boolean'), 'b5' => array('optional' => TRUE, 'type' => 'boolean'), 'b6' => array('optional' => TRUE, 'type' => 'boolean'));
     $this->mockReflectionService->expects($this->once())->method('getMethodParameters')->with('Tx_SomeExtensionName_Command_DefaultCommandController', 'listCommand')->will($this->returnValue($methodParameters));
     $expectedArguments = array('b1' => TRUE, 'b2' => TRUE, 'b3' => TRUE, 'b4' => FALSE, 'b5' => FALSE, 'b6' => FALSE);
     $request = $this->requestBuilder->build('some_extension_name:default:list --b2 y --b1 1 --b3 true --b4 false --b5 n --b6 0');
     $this->assertEquals($expectedArguments, $request->getArguments());
 }
开发者ID:plan2net,项目名称:TYPO3.CMS,代码行数:12,代码来源:RequestBuilderTest.php

示例6: prepareArgumentsRegistersAnnotationBasedArgumentsWithDescriptionIfDebugModeIsEnabled

 /**
  * @test
  */
 public function prepareArgumentsRegistersAnnotationBasedArgumentsWithDescriptionIfDebugModeIsEnabled()
 {
     $dataCacheMock = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, array(), array(), '', false);
     $dataCacheMock->expects($this->any())->method('has')->will($this->returnValue(true));
     $dataCacheMock->expects($this->any())->method('get')->will($this->returnValue(array()));
     $viewHelper = new \TYPO3\CMS\Fluid\Tests\Unit\Core\Fixtures\TestViewHelper();
     $this->mockReflectionService->expects($this->once())->method('getMethodParameters')->with(\TYPO3\CMS\Fluid\Tests\Unit\Core\Fixtures\TestViewHelper::class, 'render')->will($this->returnValue($this->fixtureMethodParameters));
     $this->mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(\TYPO3\CMS\Fluid\Tests\Unit\Core\Fixtures\TestViewHelper::class, 'render')->will($this->returnValue($this->fixtureMethodTags));
     $viewHelper->injectReflectionService($this->mockReflectionService);
     $expected = array('param1' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param1', 'integer', 'P1 Stuff', true, null, true), 'param2' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param2', 'array', 'P2 Stuff', true, null, true), 'param3' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param3', 'string', 'P3 Stuff', false, 'default', true));
     $this->assertEquals($expected, $viewHelper->prepareArguments(), 'Annotation based arguments were not registered.');
 }
开发者ID:TYPO3Incubator,项目名称:TYPO3.CMS,代码行数:15,代码来源:AbstractViewHelperTest.php

示例7: convertFromShouldThrowExceptionIfRequiredConstructorParameterWasNotFound

 /**
  * @test
  * @expectedException \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException
  */
 public function convertFromShouldThrowExceptionIfRequiredConstructorParameterWasNotFound()
 {
     $source = array('propertyX' => 'bar');
     $object = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor('param1');
     $convertedChildProperties = array('property2' => 'bar');
     $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, '__construct')->will($this->returnValue(array('property1' => array('optional' => false))));
     $this->mockReflectionService->expects($this->any())->method('hasMethod')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, '__construct')->will($this->returnValue(true));
     $this->mockContainer->expects($this->any())->method('getImplementationClassName')->will($this->returnValue(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class));
     $configuration = $this->buildConfiguration(array(PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true));
     $result = $this->converter->convertFrom($source, \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, $convertedChildProperties, $configuration);
     $this->assertSame($object, $result);
 }
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:16,代码来源:PersistentObjectConverterTest.php

示例8: prepareArgumentsRegistersAnnotationBasedArgumentsWithoutDescriptionIfDebugModeIsDisabled

 /**
  * @test
  */
 public function prepareArgumentsRegistersAnnotationBasedArgumentsWithoutDescriptionIfDebugModeIsDisabled()
 {
     \TYPO3\CMS\Fluid\Fluid::$debugMode = FALSE;
     $dataCacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array(), array(), '', FALSE);
     $dataCacheMock->expects($this->any())->method('has')->will($this->returnValue(TRUE));
     $dataCacheMock->expects($this->any())->method('get')->will($this->returnValue(array()));
     $viewHelper = new \TYPO3\CMS\Fluid\Tests\Unit\Core\Fixtures\TestViewHelper2();
     $this->mockReflectionService->expects($this->once())->method('getMethodParameters')->with('TYPO3\\CMS\\Fluid\\Tests\\Unit\\Core\\Fixtures\\TestViewHelper2', 'render')->will($this->returnValue($this->fixtureMethodParameters));
     $this->mockReflectionService->expects($this->never())->method('getMethodTagsValues');
     $viewHelper->injectReflectionService($this->mockReflectionService);
     $expected = array('param1' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param1', 'integer', '', TRUE, NULL, TRUE), 'param2' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param2', 'array', '', TRUE, NULL, TRUE), 'param3' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param3', 'string', '', FALSE, 'default', TRUE));
     $this->assertEquals($expected, $viewHelper->prepareArguments(), 'Annotation based arguments were not registered.');
 }
开发者ID:khanhdeux,项目名称:typo3test,代码行数:16,代码来源:AbstractViewHelperTest.php

示例9: initializeExtbaseFramework

 /**
  * @return void
  */
 protected function initializeExtbaseFramework()
 {
     // initialize cache manager
     $this->cacheManager = $GLOBALS['typo3CacheManager'];
     // inject content object into the configuration manager
     $this->configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
     $contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
     $this->configurationManager->setContentObject($contentObject);
     $this->typoScriptService->makeTypoScriptBackup();
     // load extbase typoscript
     TypoScriptService::loadTypoScriptFromFile('EXT:extbase/ext_typoscript_setup.txt');
     TypoScriptService::loadTypoScriptFromFile('EXT:ap_ldap_auth/ext_typoscript_setup.txt');
     $this->configurationManager->setConfiguration($GLOBALS['TSFE']->tmpl->setup);
     $this->configureObjectManager();
     // initialize reflection
     $this->reflectionService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService');
     $this->reflectionService->setDataCache($this->cacheManager->getCache('extbase_reflection'));
     if (!$this->reflectionService->isInitialized()) {
         $this->reflectionService->initialize();
     }
     // initialize persistence
     $this->persistenceManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
 }
开发者ID:LiaraAlis,项目名称:typo3-ap_ldap_auth,代码行数:26,代码来源:AbstractAuthenticationService.php

示例10: 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;
 }
开发者ID:ecodev,项目名称:newsletter,代码行数:39,代码来源:Api.php

示例11: secureActionArguments

 public function secureActionArguments($arguments, $request, $controllerClassName)
 {
     // look for @modificationAllowed and @creationAllowed annotations on action methods
     $actionMethodName = $request->getControllerActionName() . 'Action';
     $tags = $this->reflectionService->getMethodTagsValues($controllerClassName, $actionMethodName);
     if (array_key_exists('modificationAllowed', $tags)) {
         $modificationAllowed = $tags['modificationAllowed'];
     } else {
         $modificationAllowed = array();
     }
     if (array_key_exists('creationAllowed', $tags)) {
         $creationAllowed = $tags['creationAllowed'];
     } else {
         $creationAllowed = array();
     }
     // modification and creation are disabled by default on all arguments
     foreach ($arguments->getArgumentNames() as $argumentName) {
         $conf = $arguments[$argumentName]->getPropertyMappingConfiguration();
         $options = array();
         $key = \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED;
         if (!in_array($argumentName, $modificationAllowed)) {
             $options[$key] = false;
         } else {
             $options[$key] = true;
         }
         $key = \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED;
         if (!in_array($argumentName, $creationAllowed)) {
             $options[$key] = false;
         } else {
             $options[$key] = true;
         }
         // set sane defaults
         #$conf->setTypeConverterOptions('TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter', $options);
     }
 }
开发者ID:electricretina,项目名称:cicbase,代码行数:35,代码来源:ControllerSecurityService.php

示例12: getClassNamesInNamespace

	/**
	 * Get all class names inside this namespace and return them as array.
	 *
	 * @param string $namespace
	 * @return array Array of all class names inside a given namespace.
	 */
	protected function getClassNamesInNamespace($namespace) {
		$affectedViewHelperClassNames = array();

		$allViewHelperClassNames = $this->reflectionService->getAllSubClassNamesForClass(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class);
		foreach ($allViewHelperClassNames as $viewHelperClassName) {
			if ($this->reflectionService->isClassAbstract($viewHelperClassName)) {
				continue;
			}
			if (strncmp($namespace, $viewHelperClassName, strlen($namespace)) === 0) {
				$affectedViewHelperClassNames[] = $viewHelperClassName;
			}
		}
		sort($affectedViewHelperClassNames);
		return $affectedViewHelperClassNames;
	}
开发者ID:,项目名称:,代码行数:21,代码来源:

示例13: checkRequestHash

 /**
  * 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 \TYPO3\CMS\Extbase\Mvc\Exception\InvalidOrNoRequestHashException In case request hash checking failed
  * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
  */
 protected function checkRequestHash()
 {
     if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
         // If the new property mapper is enabled, the request hash is not needed anymore.
         return;
     }
     if (!$this->request instanceof \TYPO3\CMS\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() == \TYPO3\CMS\Extbase\Mvc\Controller\Argument::ORIGIN_NEWLY_CREATED || $argument->getOrigin() == \TYPO3\CMS\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 \TYPO3\CMS\Extbase\Mvc\Exception\InvalidOrNoRequestHashException('Request hash (HMAC) checking failed. The parameter __hmac was invalid or not set, and objects were modified.', 1255082824);
         }
     }
 }
开发者ID:khanhdeux,项目名称:typo3test,代码行数:36,代码来源:ActionController.php

示例14: 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++;
     }
 }
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:40,代码来源:AbstractViewHelper.php

示例15: 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);
	}
开发者ID:,项目名称:,代码行数:70,代码来源:


注:本文中的TYPO3\CMS\Extbase\Reflection\ReflectionService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。