/** * @see Sphpdox\Element.Element::__toString() */ public function __toString() { $name = $this->reflection->getName(); $title = str_replace('\\', '\\\\', $name); //$title = $name; $string = str_repeat('-', strlen($title)) . "\n"; $string .= $title . "\n"; $string .= str_repeat('-', strlen($title)) . "\n\n"; $string .= $this->getNamespaceElement(); if ($this->reflection->isInterface()) { $string .= '.. php:interface:: '; } elseif ($this->reflection->isTrait()) { $string .= '.. php:trait:: '; } else { $string .= '.. php:class:: '; } $string .= $this->reflection->getShortName(); $parser = $this->getParser(); if ($description = $parser->getDescription()) { $string .= "\n\n"; $string .= $this->indent($description, 4); } foreach ($this->getSubElements() as $element) { $e = $element->__toString(); if ($e) { $string .= "\n\n"; $string .= $this->indent($e, 4); } } $string .= "\n\n"; // Finally, fix some whitespace errors $string = preg_replace('/^\\s+$/m', '', $string); $string = preg_replace('/ +$/m', '', $string); return $string; }
/** * Add an interface for child * * @param string|ReflectionClass|ParsedClass $interface * * @throws \InvalidArgumentException If object is not an interface */ public function addInterface($interface) { $interfaceName = $interface; if ($interface instanceof ReflectionClass || $interface instanceof ParsedClass) { if (!$interface->isInterface()) { throw new \InvalidArgumentException("Interface expected to add"); } $interfaceName = $interface->name; } // Use absolute namespace to prevent NS-conflicts $this->interfaces[] = '\\' . ltrim($interfaceName, '\\'); }
/** * * @param ReflectionClass $reflection * @return string */ protected static function getObjectType(ReflectionClass $reflection) { return $reflection->isTrait() ? "Trait" : ($reflection->isInterface() ? "Interface" : "Class"); }