/** * Registers a parent class or interface with this constant. * * @param ClassDescriptor|InterfaceDescriptor|null $parent * * @throws \InvalidArgumentException if anything other than a class, interface or null was passed. * * @return void */ public function setParent($parent) { if (!$parent instanceof ClassDescriptor && !$parent instanceof InterfaceDescriptor && $parent !== null) { throw new \InvalidArgumentException('Constants can only have an interface or class as parent'); } $this->setFullyQualifiedStructuralElementName($parent->getFullyQualifiedStructuralElementName() . '::' . $this->getName()); $this->parent = $parent; }
/** * Export the given reflected interface definition to the provided parent 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 Element to augment. * @param InterfaceDescriptor $interface Element to export. * * @return \DOMElement */ public function convert(\DOMElement $parent, InterfaceDescriptor $interface) { $child = new \DOMElement('interface'); $parent->appendChild($child); /** @var InterfaceDescriptor $parentInterface */ foreach ($interface->getParent() as $parentInterface) { $parentFqcn = is_string($parentInterface) === false ? $parentInterface->getFullyQualifiedStructuralElementName() : $parentInterface; $child->appendChild(new \DOMElement('extends', $parentFqcn)); } $namespace = $interface->getNamespace()->getFullyQualifiedStructuralElementName(); $child->setAttribute('namespace', ltrim($namespace, '\\')); $child->setAttribute('line', $interface->getLine()); $child->appendChild(new \DOMElement('name', $interface->getName())); $child->appendChild(new \DOMElement('full_name', $interface->getFullyQualifiedStructuralElementName())); $this->docBlockConverter->convert($child, $interface); foreach ($interface->getConstants() as $constant) { $this->constantConverter->convert($child, $constant); } foreach ($interface->getMethods() as $method) { $this->methodConverter->convert($child, $method); } return $child; }