Example #1
0
 /**
  * Converts the given parameter reflection into an information array
  *
  * @param ParameterReflection $parameter The parameter to reflect
  * @param int $parameterPosition
  * @param MethodReflection|NULL $method
  * @return array Parameter information array
  */
 protected function convertParameterReflectionToArray(ParameterReflection $parameter, $parameterPosition, MethodReflection $method = null)
 {
     $parameterInformation = ['position' => $parameterPosition, 'byReference' => $parameter->isPassedByReference(), 'array' => $parameter->isArray(), 'optional' => $parameter->isOptional(), 'allowsNull' => $parameter->allowsNull()];
     $parameterClass = $parameter->getClass();
     $parameterInformation['class'] = $parameterClass !== null ? $parameterClass->getName() : null;
     if ($parameter->isDefaultValueAvailable()) {
         $parameterInformation['defaultValue'] = $parameter->getDefaultValue();
     }
     if ($parameterClass !== null) {
         $parameterInformation['type'] = $parameterClass->getName();
     } elseif ($method !== null) {
         $methodTagsAndValues = $this->getMethodTagsValues($method->getDeclaringClass()->getName(), $method->getName());
         if (isset($methodTagsAndValues['param']) && isset($methodTagsAndValues['param'][$parameterPosition])) {
             $explodedParameters = explode(' ', $methodTagsAndValues['param'][$parameterPosition]);
             if (count($explodedParameters) >= 2) {
                 if (TypeHandlingUtility::isSimpleType($explodedParameters[0])) {
                     // ensure that short names of simple types are resolved correctly to the long form
                     // this is important for all kinds of type checks later on
                     $typeInfo = TypeHandlingUtility::parseType($explodedParameters[0]);
                     $parameterInformation['type'] = $typeInfo['type'];
                 } else {
                     $parameterInformation['type'] = $explodedParameters[0];
                 }
             }
         }
     }
     if (isset($parameterInformation['type']) && $parameterInformation['type'][0] === '\\') {
         $parameterInformation['type'] = substr($parameterInformation['type'], 1);
     }
     return $parameterInformation;
 }
Example #2
0
 /**
  * @param ParameterReflection $parameterReflection
  * @param string $argumentName
  * @return array
  */
 protected function parseDocCommentOfArgument(ParameterReflection $parameterReflection, $argumentName)
 {
     $docCommentParser = new DocCommentParser();
     $docCommentParser->parseDocComment($parameterReflection->getDeclaringFunction()->getDocComment());
     $parameterAnnotations = $docCommentParser->getTagValues('param');
     foreach ($parameterAnnotations as $parameterAnnotation) {
         list($type, $name, $description) = explode(' ', $parameterAnnotation, 3);
         if ($name === '$' . $argumentName) {
             return [$type, $description];
         }
     }
     return ['mixed', 'Unknown argument - may not be supported by command controller!'];
 }
 /**
  * Converts the given parameter reflection into an information array
  *
  * @param ParameterReflection $parameter The parameter to reflect
  * @param integer $parameterPosition
  * @param MethodReflection|NULL $method
  * @return array Parameter information array
  */
 protected function convertParameterReflectionToArray(ParameterReflection $parameter, $parameterPosition, MethodReflection $method = NULL)
 {
     $parameterInformation = array('position' => $parameterPosition, 'byReference' => $parameter->isPassedByReference(), 'array' => $parameter->isArray(), 'optional' => $parameter->isOptional(), 'allowsNull' => $parameter->allowsNull());
     $parameterClass = $parameter->getClass();
     $parameterInformation['class'] = $parameterClass !== NULL ? $parameterClass->getName() : NULL;
     if ($parameter->isDefaultValueAvailable()) {
         $parameterInformation['defaultValue'] = $parameter->getDefaultValue();
     }
     if ($parameterClass !== NULL) {
         $parameterInformation['type'] = $parameterClass->getName();
     } elseif ($method !== NULL) {
         $methodTagsAndValues = $this->getMethodTagsValues($method->getDeclaringClass()->getName(), $method->getName());
         if (isset($methodTagsAndValues['param']) && isset($methodTagsAndValues['param'][$parameterPosition])) {
             $explodedParameters = explode(' ', $methodTagsAndValues['param'][$parameterPosition]);
             if (count($explodedParameters) >= 2) {
                 $parameterInformation['type'] = $explodedParameters[0];
             }
         }
     }
     if (isset($parameterInformation['type']) && $parameterInformation['type'][0] === '\\') {
         $parameterInformation['type'] = substr($parameterInformation['type'], 1);
     }
     return $parameterInformation;
 }