Nette\PhpGenerator\Property::from PHP Method

from() public static method

public static from ( ReflectionProperty $from ) : self
$from ReflectionProperty
return self
    public static function from(\ReflectionProperty $from)
    {
        $prop = new static($from->getName());
        $defaults = $from->getDeclaringClass()->getDefaultProperties();
        $prop->value = isset($defaults[$prop->name]) ? $defaults[$prop->name] : NULL;
        $prop->static = $from->isStatic();
        $prop->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public');
        $prop->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
        return $prop;
    }

Usage Example

Beispiel #1
0
 /**
  * @param  \ReflectionClass|string
  * @return self
  */
 public static function from($from)
 {
     $from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from);
     if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
         $class = new static('anonymous');
     } else {
         $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
     }
     $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
     $class->final = $from->isFinal() && $class->type === 'class';
     $class->abstract = $from->isAbstract() && $class->type === 'class';
     $class->implements = $from->getInterfaceNames();
     $class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
     if ($from->getParentClass()) {
         $class->extends = $from->getParentClass()->getName();
         $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
     }
     foreach ($from->getProperties() as $prop) {
         if ($prop->getDeclaringClass()->getName() === $from->getName()) {
             $class->properties[$prop->getName()] = Property::from($prop);
         }
     }
     foreach ($from->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() === $from->getName()) {
             $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
         }
     }
     return $class;
 }
All Usage Examples Of Nette\PhpGenerator\Property::from