/** * @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 a trait for child * * @param string|ReflectionClass|ParsedClass $trait * * @throws \InvalidArgumentException If object is not a trait */ public function addTrait($trait) { $traitName = $trait; if ($trait instanceof ReflectionClass || $trait instanceof ParsedClass) { if (!$trait->isTrait()) { throw new \InvalidArgumentException("Trait expected to add"); } $traitName = $trait->name; } // Use absolute namespace to prevent NS-conflicts $this->traits[] = '\\' . ltrim($traitName, '\\'); }
/** * Adjust definition of original class source to enable extending * * @param ParsedClass $class Instance of class reflection * @param string $source Source code * @param string $newParentName New name for the parent class * * @return string Replaced code for class */ private function adjustOriginalClass($class, $source, $newParentName) { $type = $this->kernel->hasFeature(Features::USE_TRAIT) && $class->isTrait() ? 'trait' : 'class'; $source = preg_replace("/{$type}\\s+(" . $class->getShortName() . ')(\\b)/iS', "{$type} {$newParentName}\$2", $source); if ($class->isFinal()) { // Remove final from class, child will be final instead $source = str_replace("final {$type}", $type, $source); } return $source; }
/** * Returns list of introduction advices from advisor * * @param ReflectionClass|ParsedReflectionClass $class Class to inject advices * @param Aop\IntroductionAdvisor $advisor Advisor for class * @param string $advisorId Identifier of advisor * * @return array */ private function getIntroductionFromAdvisor($class, $advisor, $advisorId) { // Do not make introduction for traits if ($class->isTrait()) { return array(); } /** @var $advice Aop\IntroductionInfo */ $advice = $advisor->getAdvice(); $classAdvices[AspectContainer::INTRODUCTION_TRAIT_PREFIX][$advisorId] = $advice; return $classAdvices; }
/** * * @param ReflectionClass $reflection * @return string */ protected static function getObjectType(ReflectionClass $reflection) { return $reflection->isTrait() ? "Trait" : ($reflection->isInterface() ? "Interface" : "Class"); }