/**
  * Initializes this descriptor.
  */
 public function __construct($name)
 {
     $this->setName($name);
     $this->setSettings(new Settings());
     $namespace = new NamespaceDescriptor();
     $namespace->setName('\\');
     $namespace->setFullyQualifiedStructuralElementName('\\');
     $this->setNamespace($namespace);
     $this->setFiles(new Collection());
     $this->setIndexes(new Collection());
 }
 /**
  * @covers phpDocumentor\Descriptor\NamespaceDescriptor::__construct
  * @covers phpDocumentor\Descriptor\NamespaceDescriptor::getTraits
  * @covers phpDocumentor\Descriptor\NamespaceDescriptor::setTraits
  */
 public function testSetAndGetTraits()
 {
     $collection = new Collection();
     $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $this->fixture->getTraits());
     $this->fixture->setTraits($collection);
     $this->assertSame($collection, $this->fixture->getTraits());
 }
 /**
  * Creates a tree of NamespaceDescriptors based on the provided FQNN (namespace name).
  *
  * This method will examine the namespace name and create a namespace descriptor for each part of
  * the FQNN if it doesn't exist in the namespaces field of the current namespace (starting with the root
  * Namespace in the Project Descriptor),
  *
  * As an intended side effect this method also populates the *elements* index of the ProjectDescriptor with all
  * created NamespaceDescriptors. Each index key is prefixed with a tilde (~) so that it will not conflict with
  * other FQSEN's, such as classes or interfaces.
  *
  * @param ProjectDescriptor $project
  * @param string            $namespaceName A FQNN of the namespace (and parents) to create.
  *
  * @see ProjectDescriptor::getNamespace() for the root namespace.
  * @see NamespaceDescriptor::getNamespaces() for the child namespaces of a given namespace.
  *
  * @return void
  */
 protected function createNamespaceDescriptorTree(ProjectDescriptor $project, $namespaceName)
 {
     $parts = explode('\\', ltrim($namespaceName, '\\'));
     $fqnn = '';
     // this method does not use recursion to traverse the tree but uses a pointer that will be overridden with the
     // next item that is to be traversed (child namespace) at the end of the loop.
     $pointer = $project->getNamespace();
     foreach ($parts as $part) {
         $fqnn .= '\\' . $part;
         if ($pointer->getChildren()->get($part)) {
             $pointer = $pointer->getChildren()->get($part);
             continue;
         }
         // namespace does not exist, create it
         $interimNamespaceDescriptor = new NamespaceDescriptor();
         $interimNamespaceDescriptor->setParent($pointer);
         $interimNamespaceDescriptor->setName($part);
         $interimNamespaceDescriptor->setFullyQualifiedStructuralElementName($fqnn);
         // add to the pointer's list of children
         $pointer->getChildren()->set($part, $interimNamespaceDescriptor);
         // add to index
         $project->getIndexes()->elements['~' . $fqnn] = $interimNamespaceDescriptor;
         $project->getIndexes()->get('namespaces', new Collection())->add($interimNamespaceDescriptor);
         // move pointer forward
         $pointer = $interimNamespaceDescriptor;
     }
 }
Esempio n. 4
0
 /**
  * Builds a tree of namespace subgraphs with their classes associated.
  *
  * @param GraphVizGraph       $graph
  * @param NamespaceDescriptor $namespace
  *
  * @return void
  */
 protected function buildNamespaceTree(GraphVizGraph $graph, NamespaceDescriptor $namespace)
 {
     $full_namespace_name = $namespace->getFullyQualifiedStructuralElementName();
     if ($full_namespace_name == '\\') {
         $full_namespace_name = 'Global';
     }
     $sub_graph = GraphVizGraph::create('cluster_' . $full_namespace_name)->setLabel($namespace->getName() == '\\' ? 'Global' : $namespace->getName())->setStyle('rounded')->setColor('gray')->setFontColor('gray')->setFontSize('11')->setRankDir('LR');
     $elements = array_merge($namespace->getClasses()->getAll(), $namespace->getInterfaces()->getAll(), $namespace->getTraits()->getAll());
     /** @var ClassDescriptor|InterfaceDescriptor|TraitDescriptor $sub_element */
     foreach ($elements as $sub_element) {
         $node = Node::create($sub_element->getFullyQualifiedStructuralElementName(), $sub_element->getName())->setShape('box')->setFontName($this->nodeFont)->setFontSize('11');
         if ($sub_element instanceof ClassDescriptor && $sub_element->isAbstract()) {
             $node->setLabel('<«abstract»<br/>' . $sub_element->getName() . '>');
         }
         //$full_name = $sub_element->getFullyQualifiedStructuralElementName();
         //$node->setURL($this->class_paths[$full_name]);
         //$node->setTarget('_parent');
         $this->nodeCache[$sub_element->getFullyQualifiedStructuralElementName()] = $node;
         $sub_graph->setNode($node);
     }
     foreach ($namespace->getChildren()->getAll() as $element) {
         $this->buildNamespaceTree($sub_graph, $element);
     }
     $graph->addGraph($sub_graph);
 }
 /**
  * Generates a URL from the given node or returns false if unable.
  *
  * @param string|Descriptor\NamespaceDescriptor $node
  *
  * @return string|false
  */
 public function __invoke($node)
 {
     $converter = new QualifiedNameToUrlConverter();
     return '/namespaces/' . $converter->fromNamespace($node->getFullyQualifiedStructuralElementName()) . '.html';
 }