コード例 #1
0
 /**
  * Creates a Descriptor from the provided data.
  *
  * @param ClassReflector $data
  *
  * @return ClassDescriptor
  */
 public function create($data)
 {
     $classDescriptor = new ClassDescriptor();
     $classDescriptor->setFullyQualifiedStructuralElementName($data->getName());
     $classDescriptor->setName($data->getShortName());
     $classDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: '');
     $classDescriptor->setLine($data->getLinenumber());
     $classDescriptor->setParent($data->getParentClass());
     $classDescriptor->setAbstract($data->isAbstract());
     $classDescriptor->setFinal($data->isFinal());
     // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself
     $classDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace()));
     foreach ($data->getInterfaces() as $interfaceClassName) {
         $classDescriptor->getInterfaces()->set($interfaceClassName, $interfaceClassName);
     }
     $fqcn = $classDescriptor->getFullyQualifiedStructuralElementName();
     $namespace = substr($fqcn, 0, strrpos($fqcn, '\\'));
     $classDescriptor->setNamespace($namespace);
     $this->assembleDocBlock($data->getDocBlock(), $classDescriptor);
     $this->addConstants($data->getConstants(), $classDescriptor);
     $this->addProperties($data->getProperties(), $classDescriptor);
     $this->addMethods($data->getMethods(), $classDescriptor);
     $this->addUses($data->getTraits(), $classDescriptor);
     return $classDescriptor;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * @param ClassDescriptor|TraitDescriptor $parent
  */
 public function setParent($parent)
 {
     $this->setFullyQualifiedStructuralElementName($parent->getFullyQualifiedStructuralElementName() . '::' . $this->getName());
     $this->parent = $parent;
 }
コード例 #4
0
ファイル: Xml.php プロジェクト: michaelyin1/Modern-Toolkit
 /**
  * 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 ClassDescriptor $class  The data source.
  * @param \DOMElement     $child  Optional: child element to use instead of creating a
  *      new one on the $parent.
  *
  * @return void
  */
 public function buildClass(\DOMElement $parent, ClassDescriptor $class, \DOMElement $child = null)
 {
     if (!$child) {
         $child = new \DOMElement('class');
         $parent->appendChild($child);
     }
     $child->setAttribute('final', $class->isFinal() ? 'true' : 'false');
     $child->setAttribute('abstract', $class->isAbstract() ? 'true' : 'false');
     $parentFqcn = is_string($class->getParent()) ? $class->getParent() : $class->getParent()->getFullyQualifiedStructuralElementName();
     $child->appendChild(new \DOMElement('extends', $parentFqcn));
     /** @var InterfaceDescriptor $interface */
     foreach ($class->getInterfaces() as $interface) {
         $interfaceFcqn = is_string($interface) ? $interface : $interface->getFullyQualifiedStructuralElementName();
         $child->appendChild(new \DOMElement('implements', $interfaceFcqn));
     }
     if ($child === null) {
         $child = new \DOMElement('interface');
         $parent->appendChild($child);
     }
     $namespace = $class->getNamespace()->getFullyQualifiedStructuralElementName();
     $child->setAttribute('namespace', ltrim($namespace, '\\'));
     $child->setAttribute('line', $class->getLine());
     $child->appendChild(new \DOMElement('name', $class->getName()));
     $child->appendChild(new \DOMElement('full_name', $class->getFullyQualifiedStructuralElementName()));
     $this->buildDocBlock($child, $class);
     foreach ($class->getConstants() as $constant) {
         // TODO #840: Workaround; for some reason there are NULLs in the constants array.
         if ($constant) {
             $this->buildConstant($child, $constant);
         }
     }
     foreach ($class->getProperties() as $property) {
         // TODO #840: Workaround; for some reason there are NULLs in the properties array.
         if ($property) {
             $this->buildProperty($child, $property);
         }
     }
     foreach ($class->getMethods() as $method) {
         // TODO #840: Workaround; for some reason there are NULLs in the methods array.
         if ($method) {
             $this->buildMethod($child, $method);
         }
     }
 }
コード例 #5
0
 /**
  * Generates a URL from the given node or returns false if unable.
  *
  * @param string|Descriptor\ClassDescriptor $node
  *
  * @return string|false
  */
 public function __invoke($node)
 {
     $converter = new QualifiedNameToUrlConverter();
     return $node instanceof Descriptor\DescriptorAbstract ? '/classes/' . $converter->fromClass($node->getFullyQualifiedStructuralElementName()) . '.html' : false;
 }