from() public static method

public static from ( $from ) : self
return self
示例#1
0
 /**
  * @param string $className
  * @return string
  */
 public function generate($className)
 {
     if (!class_exists($className)) {
         throw new InvalidArgumentException("Unknown class {$className}. Check for typos in class name and make sure" . " that given class is properly loaded.");
     }
     $origin = new ReflectionClass($className);
     $interface = ClassType::from(self::ACCESSOR_INTERFACE);
     $namespace = new PhpNamespace($this->naming->getNamespace());
     $class = $namespace->addClass($this->naming->deriveClassName($className));
     $class->addDocument("This class was automatically generated by Markatom/Accessor library.");
     $class->addImplement(self::ACCESSOR_INTERFACE);
     $class->addConst('TARGET', $origin->getName());
     $class->addProperty('writer')->setVisibility('private');
     $class->setMethods($interface->getMethods());
     $class->getMethod('read')->setVisibility('public')->setBody($this->generateReadBody($origin));
     $class->getMethod('write')->setVisibility('public')->setBody($this->generateWriteBody($origin));
     return (string) $namespace;
 }