public static function fromReflection(ZendL_Reflection_Class $reflectionClass) { $class = new self(); $class->setSourceContent($class->getSourceContent()); $class->setSourceDirty(false); if ($reflectionClass->getDocComment() != '') { $class->setDocblock(ZendL_Tool_CodeGenerator_Php_Docblock::fromReflection($reflectionClass->getDocblock())); } $class->setAbstract($reflectionClass->isAbstract()); $class->setName($reflectionClass->getName()); if ($parentClass = $reflectionClass->getParentClass()) { $class->setExtendedClass($parentClass->getName()); } $class->setImplementedInterfaces($reflectionClass->getInterfaceNames()); $properties = array(); foreach ($reflectionClass->getProperties() as $reflectionProperty) { if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) { $properties[] = ZendL_Tool_CodeGenerator_Php_Property::fromReflection($reflectionProperty); } } $class->setProperties($properties); $methods = array(); foreach ($reflectionClass->getMethods() as $reflectionMethod) { if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) { $methods[] = ZendL_Tool_CodeGenerator_Php_Method::fromReflection($reflectionMethod); } } $class->setMethods($methods); return $class; }
public function setProperty($property) { if (is_array($property)) { $property = new ZendL_Tool_CodeGenerator_Php_Property($property); $propertyName = $property->getName(); } elseif ($property instanceof ZendL_Tool_CodeGenerator_Php_Property) { $propertyName = $property->getName(); } else { require_once 'ZendL/Tool/CodeGenerator/Php/Exception.php'; throw new ZendL_Tool_CodeGenerator_Php_Exception('setProperty() expects either an array of property options or an instance of ZendL_Tool_CodeGenerator_Php_Property'); } if (isset($this->_properties[$propertyName])) { require_once 'ZendL/Tool/CodeGenerator/Php/Exception.php'; throw new ZendL_Tool_CodeGenerator_Php_Exception('A property by name ' . $propertyName . ' already exists in this class.'); } $this->_properties->append($property); return $this; }