/** * Exports the given reflection object to the parent XML element. * * This method creates a new child element on the given parent XML element * and takes the properties of the Reflection argument and sets the * elements and attributes on the child. * * If a child DOMElement is provided then the properties and attributes are * set on this but the child element is not appended onto the parent. This * is the responsibility of the invoker. Essentially this means that the * $parent argument is ignored in this case. * * @param \DOMElement $parent The parent element * to augment. * @param \phpDocumentor\Reflection\BaseReflector $element The data source. * * @return void */ public function export(\DOMElement $parent, $element) { $docblock = $element->getDocBlock(); if (!$docblock) { $parent->setAttribute('package', $element->getDefaultPackageName()); return; } $child = new \DOMElement('docblock'); $parent->appendChild($child); // TODO: custom attached member variable, make real $child->setAttribute('line', $docblock->line_number); $this->addDescription($child, $docblock); $this->addLongDescription($child, $docblock); $this->addTags($child, $docblock->getTags(), $element); $this->setParentsPackage($parent, $docblock, $element); }
/** * Sets the package of the parent element. * * This method inspects the current DocBlock and extract an @package * element. If that tag is present than the associated element's package * name is set to that value. * * If no @package tag is present in the DocBlock then the default package * name is set. * * @param \DOMElement $parent * @param DocBlock $docblock * @param BaseReflector $element * * @return void */ protected function setParentsPackage(\DOMElement $parent, DocBlock $docblock, $element) { /** @var \phpDocumentor\Reflection\DocBlock\Tag $package */ $package = current($docblock->getTagsByName('package')); /** @var \phpDocumentor\Reflection\DocBlock\Tag $subpackage */ $subpackage = current($docblock->getTagsByName('subpackage')); $package_name = ''; if ($package) { $package_name = str_replace(array('.', '_'), '\\', $package->getContent() . ($subpackage ? '\\' . $subpackage->getContent() : '')); } if (!$package_name) { $package_name = $element->getDefaultPackageName(); } $parent->setAttribute('package', $package_name); }