Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * fromReflection() - build a Code Generation PHP Object from a Class Reflection
  *
  * @param \Zend\Reflection\ReflectionClass $reflectionClass
  * @return \Zend\CodeGenerator\PHP\PHPClass
  */
 public static function fromReflection(\Zend\Reflection\ReflectionClass $reflectionClass)
 {
     $class = new self();
     $class->setSourceContent($class->getSourceContent());
     $class->setSourceDirty(false);
     if ($reflectionClass->getDocComment() != '') {
         $class->setDocblock(PHPDocblock::fromReflection($reflectionClass->getDocblock()));
     }
     $class->setAbstract($reflectionClass->isAbstract());
     // set the namespace
     if ($reflectionClass->inNamespace()) {
         $class->setNamespaceName($reflectionClass->getNamespaceName());
     }
     $class->setName($reflectionClass->getName());
     if ($parentClass = $reflectionClass->getParentClass()) {
         $class->setExtendedClass($parentClass->getName());
         $interfaces = array_diff($reflectionClass->getInterfaces(), $parentClass->getInterfaces());
     } else {
         $interfaces = $reflectionClass->getInterfaces();
     }
     $interfaceNames = array();
     foreach ($interfaces as $interface) {
         $interfaceNames[] = $interface->getName();
     }
     $class->setImplementedInterfaces($interfaceNames);
     $properties = array();
     foreach ($reflectionClass->getProperties() as $reflectionProperty) {
         if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) {
             $properties[] = PHPProperty::fromReflection($reflectionProperty);
         }
     }
     $class->setProperties($properties);
     $methods = array();
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) {
             $methods[] = PHPMethod::fromReflection($reflectionMethod);
         }
     }
     $class->setMethods($methods);
     return $class;
 }