/** * Serializes a Class docblock. * * @param ReflectionClass $reflection * @return void * @author pete otaqui */ public function reflectClass($reflection) { $serial = new StdClass(); $serial->name = $reflection->name; // put parent class name into $serial->extends $parentClass = (array) $reflection->getParentClass(); if (array_key_exists('name', $parentClass)) { $serial->extends = $parentClass['name']; } // abstract / final / interface $serial->abstract = $reflection->isAbstract(); $serial->final = $reflection->isFinal(); $serial->interface = $reflection->isInterface(); // put interfaces into $serial->implements $serial->implements = $reflection->getInterfaceNames(); // properties $properties = $reflection->getProperties(); $serial->properties = count($properties) ? array() : new StdClass(); foreach ($properties as $property) { $serialProp = new StdClass(); $serialProp->name = $property->name; $serialProp->access = $this->_getAccess($property); $serialProp->static = $property->isStatic(); $serialProp->type = $property->class; $serialProp->tags = array(); if ($dbProp = $property->getDocComment()) { $serialProp->description = $this->_getDescription($dbProp); foreach ($dbProp->getTags() as $tag) { $serialTag = new StdClass(); $serialTag->name = $tag->getName(); $serialTag->description = $tag->getDescription(); $serialProp->tags[] = $serialTag; } } $serial->properties[$serialProp->name] = $serialProp; unset($serialProp->name); } // methods $methods = $reflection->getMethods(); $serial->methods = count($methods) ? array() : new StdClass(); foreach ($methods as $method) { if ($method->getDeclaringClass()->name !== $reflection->name) { continue; } $serialMethod = $this->reflectMethod($method); $serial->methods[$serialMethod->name] = $serialMethod; unset($serialMethod->name); } // constants $constants = $reflection->getConstants(); $serial->constants = count($constants) ? array() : new StdClass(); foreach ($constants as $constant) { $constantSerial = new StdClass(); $constantSerial->name = $constant->getName(); $serial->constants[] = $constantSerial; } // tags // weirdly you can't "test" for the presence of a docblock // you can only try and access it, and catch thrown exception. try { $db = $reflection->getDocBlock(); $serial->description = $this->_getDescription($db); foreach ($db->getTags() as $tag) { $tagSerial = new StdClass(); $tagSerial->description = $tag->getDescription(); if ($tag->getName() == "param") { $name = str_replace('$', '', $tag->getVariableName()); $tagSerial->type = $tag->getType(); $tagSerial->access = "public"; $tagSerial->magic = true; $serial->properties[$name] = $tagSerial; } else { $tagSerial->name = $tag->getName(); $serial->tags[] = $tagSerial; } } } catch (Zend_Reflection_Exception $e) { $db = false; $serial->description = ""; } return $serial; }