/** * @param string $helperName * @param MethodReflection $methodReflection * @return string */ protected function getMethodDescription($helperName, $methodReflection) { $methodDescription = ''; $methodName = $methodReflection->getName(); $methodParameters = array(); foreach ($methodReflection->getParameters() as $parameterReflection) { $methodParameters[$parameterReflection->getName()] = $parameterReflection; } $parameterNames = array_keys($methodParameters); $methodSignature = str_replace('_', '\\_', $helperName . '.' . $methodName . '(' . implode(', ', $parameterNames) . ')'); $methodDescription .= $methodSignature . chr(10) . str_repeat('^', strlen($methodSignature)) . chr(10) . chr(10); if ($methodReflection->getDescription() !== '') { $methodDescription .= $methodReflection->getDescription() . chr(10) . chr(10); } if ($methodReflection->isTaggedWith('param')) { $paramTagValues = $methodReflection->getTagValues('param'); foreach ($paramTagValues as $paramTagValue) { $values = explode(' ', $paramTagValue, 3); list($parameterType, $parameterName) = $values; $parameterName = ltrim($parameterName, '$'); $parameterDescription = isset($values[2]) ? $values[2] : ''; $parameterOptionalSuffix = $methodParameters[$parameterName]->isOptional() ? ', *optional*' : ''; $methodDescription .= trim('* ``' . $parameterName . '`` (' . $parameterType . $parameterOptionalSuffix . ') ' . $parameterDescription) . chr(10); } $methodDescription .= chr(10); } if ($methodReflection->isTaggedWith('return')) { list($returnTagValue) = $methodReflection->getTagValues('return'); $values = explode(' ', $returnTagValue, 2); list($returnType) = $values; $returnDescription = isset($values[1]) ? $values[1] : ''; $methodDescription .= '**Return** (' . $returnType . ') ' . $returnDescription . chr(10); } return $methodDescription; }
/** * @test */ public function getArgumentDefinitionsReturnsArrayOfArgumentDefinitionIfCommandExpectsArguments() { $parameterReflection = $this->createMock(\TYPO3\Flow\Reflection\ParameterReflection::class, array(), array(array(__CLASS__, 'dummyMethod'), 'arg')); $mockReflectionService = $this->createMock(\TYPO3\Flow\Reflection\ReflectionService::class); $mockMethodParameters = array('argument1' => array('optional' => false), 'argument2' => array('optional' => true)); $mockReflectionService->expects($this->atLeastOnce())->method('getMethodParameters')->will($this->returnValue($mockMethodParameters)); $this->command->injectReflectionService($mockReflectionService); $this->methodReflection->expects($this->atLeastOnce())->method('getParameters')->will($this->returnValue(array($parameterReflection))); $this->methodReflection->expects($this->atLeastOnce())->method('getTagsValues')->will($this->returnValue(array('param' => array('@param $argument1 argument1 description', '@param $argument2 argument2 description')))); $expectedResult = array(new \TYPO3\Flow\Cli\CommandArgumentDefinition('argument1', true, 'argument1 description'), new \TYPO3\Flow\Cli\CommandArgumentDefinition('argument2', false, 'argument2 description')); $actualResult = $this->command->getArgumentDefinitions(); $this->assertEquals($expectedResult, $actualResult); }
/** * Converts the given parameter reflection into an information array * * @param ParameterReflection $parameter The parameter to reflect * @param MethodReflection $method The parameter's method * @return array Parameter information array */ protected function convertParameterReflectionToArray(ParameterReflection $parameter, MethodReflection $method = null) { $parameterInformation = [self::DATA_PARAMETER_POSITION => $parameter->getPosition()]; if ($parameter->isPassedByReference()) { $parameterInformation[self::DATA_PARAMETER_BY_REFERENCE] = true; } if ($parameter->isArray()) { $parameterInformation[self::DATA_PARAMETER_ARRAY] = true; } if ($parameter->isOptional()) { $parameterInformation[self::DATA_PARAMETER_OPTIONAL] = true; } if ($parameter->allowsNull()) { $parameterInformation[self::DATA_PARAMETER_ALLOWS_NULL] = true; } $parameterClass = $parameter->getClass(); if ($parameterClass !== null) { $parameterInformation[self::DATA_PARAMETER_CLASS] = $parameterClass->getName(); } if ($parameter->isOptional() && $parameter->isDefaultValueAvailable()) { $parameterInformation[self::DATA_PARAMETER_DEFAULT_VALUE] = $parameter->getDefaultValue(); } if ($method !== null) { $paramAnnotations = $method->isTaggedWith('param') ? $method->getTagValues('param') : []; if (isset($paramAnnotations[$parameter->getPosition()])) { $explodedParameters = explode(' ', $paramAnnotations[$parameter->getPosition()]); if (count($explodedParameters) >= 2) { $parameterType = $this->expandType($method->getDeclaringClass(), $explodedParameters[0]); $parameterInformation[self::DATA_PARAMETER_TYPE] = $this->cleanClassName($parameterType); } } if (!$parameter->isArray()) { $builtinType = $parameter->getBuiltinType(); if ($builtinType !== null) { $parameterInformation[self::DATA_PARAMETER_TYPE] = $builtinType; $parameterInformation[self::DATA_PARAMETER_SCALAR_DECLARATION] = true; } } } if (!isset($parameterInformation[self::DATA_PARAMETER_TYPE]) && $parameterClass !== null) { $parameterInformation[self::DATA_PARAMETER_TYPE] = $this->cleanClassName($parameterClass->getName()); } elseif (!isset($parameterInformation[self::DATA_PARAMETER_TYPE])) { $parameterInformation[self::DATA_PARAMETER_TYPE] = 'mixed'; } return $parameterInformation; }
/** * Compile the result of methods marked with CompileStatic into the proxy class * * @param string $className * @param ProxyClass $proxyClass * @return void * @throws ObjectException */ protected function compileStaticMethods($className, ProxyClass $proxyClass) { $methodNames = $this->reflectionService->getMethodsAnnotatedWith($className, Flow\CompileStatic::class); foreach ($methodNames as $methodName) { if (!$this->reflectionService->isMethodStatic($className, $methodName)) { throw new ObjectException(sprintf('The method %s:%s() is annotated CompileStatic so it must be static', $className, $methodName), 1476348303); } if ($this->reflectionService->isMethodPrivate($className, $methodName)) { throw new ObjectException(sprintf('The method %s:%s() is annotated CompileStatic so it must not be private', $className, $methodName), 1476348306); } $reflectedMethod = new MethodReflection($className, $methodName); $reflectedMethod->setAccessible(true); $value = $reflectedMethod->invoke(null, $this->objectManager); $compiledResult = var_export($value, true); $compiledMethod = $proxyClass->getMethod($methodName); $compiledMethod->setMethodBody('return ' . $compiledResult . ';'); } }