コード例 #1
0
 public function testParemeterReturn()
 {
     $method = new Reflection\ReflectionMethod('ZendTest\\Reflection\\TestAsset\\TestSampleClass2', 'getProp2');
     $parameters = $method->getParameters();
     $this->assertEquals(count($parameters), 2);
     $this->assertEquals(get_class(array_shift($parameters)), 'Zend\\Reflection\\ReflectionParameter');
 }
コード例 #2
0
ファイル: PhpMethod.php プロジェクト: heiglandreas/zf2
 /**
  * fromReflection()
  *
  * @param \Zend\Reflection\ReflectionMethod $reflectionMethod
  * @return \Zend\CodeGenerator\Php\PhpMethod
  */
 public static function fromReflection(\Zend\Reflection\ReflectionMethod $reflectionMethod)
 {
     $method = new self();
     $method->setSourceContent($reflectionMethod->getContents(false));
     $method->setSourceDirty(false);
     if ($reflectionMethod->getDocComment() != '') {
         $method->setDocblock(PhpDocblock::fromReflection($reflectionMethod->getDocblock()));
     }
     $method->setFinal($reflectionMethod->isFinal());
     if ($reflectionMethod->isPrivate()) {
         $method->setVisibility(self::VISIBILITY_PRIVATE);
     } elseif ($reflectionMethod->isProtected()) {
         $method->setVisibility(self::VISIBILITY_PROTECTED);
     } else {
         $method->setVisibility(self::VISIBILITY_PUBLIC);
     }
     $method->setStatic($reflectionMethod->isStatic());
     $method->setName($reflectionMethod->getName());
     foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
         $method->setParameter(PhpParameter::fromReflection($reflectionParameter));
     }
     $method->setBody($reflectionMethod->getBody());
     return $method;
 }
コード例 #3
0
ファイル: ClassMethod.php プロジェクト: RomanShumkov/zf2
 /**
  * Return method argument prototype
  * 
  * @return string
  */
 public function getPrototype()
 {
     $params = array();
     $reflectionParams = $this->getParameterAnnotations();
     foreach ($this->reflection->getParameters() as $index => $param) {
         $types = '';
         if (isset($reflectionParams[$index])) {
             $type = $reflectionParams[$index]->getType();
             $types = $this->resolveTypes($type);
         }
         $default = '';
         if ($param->isOptional()) {
             $defaultValue = var_export($param->getDefaultValue(), 1);
             $defaultValue = $this->resolveTypes($defaultValue);
             // Skip null values, but report all others
             if ('null' != strtolower($defaultValue)) {
                 $default = ' = ' . $this->resolveTypes($defaultValue);
             }
         }
         $proto = sprintf('%s $%s%s', $types, $param->getName(), $default);
         $params[] = $proto;
     }
     return implode(', ', $params);
 }