コード例 #1
0
 /**
  * @covers phpDocumentor\Descriptor\ProjectDescriptor::__construct
  * @covers phpDocumentor\Descriptor\ProjectDescriptor::setNamespace
  * @covers phpDocumentor\Descriptor\ProjectDescriptor::getNamespace
  */
 public function testGetSetNamespace()
 {
     $this->assertInstanceOf('phpDocumentor\\Descriptor\\NamespaceDescriptor', $this->fixture->getNamespace());
     $namespaceDescriptor = new NamespaceDescriptor();
     $this->fixture->setNamespace($namespaceDescriptor);
     $this->assertSame($namespaceDescriptor, $this->fixture->getNamespace());
 }
コード例 #2
0
ファイル: Graph.php プロジェクト: bbonnesoeur/phpDocumentor2
 /**
  * Creates a class inheritance diagram.
  *
  * @param ProjectDescriptor $project
  * @param Transformation    $transformation
  *
  * @return void
  */
 public function processClass(ProjectDescriptor $project, Transformation $transformation)
 {
     try {
         $this->checkIfGraphVizIsInstalled();
     } catch (\Exception $e) {
         echo $e->getMessage();
         return;
     }
     if ($transformation->getParameter('font') !== null && $transformation->getParameter('font')->getValue()) {
         $this->nodeFont = $transformation->getParameter('font')->getValue();
     } else {
         $this->nodeFont = 'Courier';
     }
     $filename = $this->getDestinationPath($transformation);
     $graph = GraphVizGraph::create()->setRankSep('1.0')->setCenter('true')->setRank('source')->setRankDir('RL')->setSplines('true')->setConcentrate('true');
     $this->buildNamespaceTree($graph, $project->getNamespace());
     $classes = $project->getIndexes()->get('classes', new Collection())->getAll();
     $interfaces = $project->getIndexes()->get('interfaces', new Collection())->getAll();
     $traits = $project->getIndexes()->get('traits', new Collection())->getAll();
     /** @var ClassDescriptor[]|InterfaceDescriptor[]|TraitDescriptor[] $containers  */
     $containers = array_merge($classes, $interfaces, $traits);
     foreach ($containers as $container) {
         $from_name = $container->getFullyQualifiedStructuralElementName();
         $parents = array();
         $implemented = array();
         if ($container instanceof ClassDescriptor) {
             if ($container->getParent()) {
                 $parents[] = $container->getParent();
             }
             $implemented = $container->getInterfaces()->getAll();
         }
         if ($container instanceof InterfaceDescriptor) {
             $parents = $container->getParent()->getAll();
         }
         /** @var string|ClassDescriptor|InterfaceDescriptor $parent */
         foreach ($parents as $parent) {
             $edge = $this->createEdge($graph, $from_name, $parent);
             $edge->setArrowHead('empty');
             $graph->link($edge);
         }
         /** @var string|ClassDescriptor|InterfaceDescriptor $parent */
         foreach ($implemented as $parent) {
             $edge = $this->createEdge($graph, $from_name, $parent);
             $edge->setStyle('dotted');
             $edge->setArrowHead('empty');
             $graph->link($edge);
         }
     }
     $graph->export('svg', $filename);
 }
コード例 #3
0
 /**
  * @covers phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::execute
  * @covers phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace
  */
 public function testAddFunctionToNamespace()
 {
     $function = new FunctionDescriptor();
     $function->setNamespace('My\\Space');
     $function->setFullyQualifiedStructuralElementName('My\\Space\\Function1');
     $this->project->getFiles()->get(0)->getFunctions()->add($function);
     // double check if a second function in the same deep namespace ends up at the right location
     $function2 = new FunctionDescriptor();
     $function2->setNamespace('My\\Space');
     $function2->setFullyQualifiedStructuralElementName('My\\Space\\Function2');
     $this->project->getFiles()->get(0)->getFunctions()->add($function2);
     $this->fixture->execute($this->project);
     $this->assertSame(array($function, $function2), $this->project->getNamespace()->getChildren()->get('My')->getChildren()->get('Space')->getFunctions()->getAll());
 }
コード例 #4
0
 /**
  * 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;
     }
 }