public static function buildFromReflection(\ReflectionClass $reflection) { $class = new self($reflection->getShortName()); $class->setNamespace($reflection->getNamespaceName()); $reflectionParentClass = $reflection->getParentClass(); if ($reflectionParentClass) { $class->setParentClassName($reflectionParentClass->getName()); } $class->setAbstract($reflection->isAbstract()); if ($interfaces = $reflection->getInterfaceNames()) { if ($reflectionParentClass) { $parentInterfaces = $reflection->getParentClass()->getInterfaceNames(); $interfaces = array_diff($interfaces, $parentInterfaces); } $class->setInterfaces($interfaces); } foreach ($reflection->getMethods() as $reflectionMethod) { if ($reflectionMethod->getDeclaringClass() == $reflection) { $method = MethodBlock::buildFromReflection($reflectionMethod); $class->addMethod($method); } } foreach ($reflection->getProperties() as $reflectionProperty) { if ($reflectionProperty->getDeclaringClass() == $reflection) { $property = PropertyBlock::buildFromReflection($reflectionProperty); $class->addProperty($property); } } foreach ($reflection->getConstants() as $name => $value) { if (!$reflection->getParentClass()->hasConstant($name)) { $class->addConstant(new ConstantBlock($name, $value)); } } return $class; }
public static function fromArray(Project $project, $array) { $class = new self($array['name'], $array['line']); $class->shortDesc = $array['short_desc']; $class->longDesc = $array['long_desc']; $class->hint = $array['hint']; $class->tags = $array['tags']; $class->namespace = $array['namespace']; $class->hash = $array['hash']; $class->file = $array['file']; $class->relativeFilePath = $array['relative_file']; $class->modifiers = $array['modifiers']; $class->fromCache = true; if ($array['is_interface']) { $class->setInterface(true); } if ($array['is_trait']) { $class->setTrait(true); } $class->aliases = $array['aliases']; $class->errors = $array['errors']; $class->parent = $array['parent']; $class->interfaces = $array['interfaces']; $class->constants = $array['constants']; $class->traits = $array['traits']; $class->setProject($project); foreach ($array['methods'] as $method) { $class->addMethod(MethodReflection::fromArray($project, $method)); } foreach ($array['properties'] as $property) { $class->addProperty(PropertyReflection::fromArray($project, $property)); } foreach ($array['constants'] as $constant) { $class->addConstant(ConstantReflection::fromArray($project, $constant)); } return $class; }