TheSeer\phpDox\Collector\SourceCollection::export PHP Method

export() public method

public export ( $collapse = false )
    public function export($collapse = false)
    {
        if (count($this->collection) == 0) {
            return $this->workDom;
        }
        $root = $this->workDom->documentElement;
        while ($root->hasChildNodes()) {
            $root->nodeValue = null;
        }
        foreach ($this->collection as $path => $file) {
            $pathInfo = new FileInfo($path);
            $dirs = explode('/', dirname($pathInfo->getRelative($this->srcDir)));
            $dirs[0] = $this->srcDir->getRealPath();
            $ctx = $root;
            foreach ($dirs as $dir) {
                $node = $ctx->queryOne('phpdox:dir[@name="' . $dir . '"]');
                if (!$node) {
                    $node = $ctx->appendElementNS('http://xml.phpdox.net/src', 'dir');
                    $node->setAttribute('name', $dir);
                }
                $ctx = $node;
            }
            $ctx->appendChild($this->workDom->importNode($file, TRUE));
        }
        $this->collection = array();
        if ($collapse) {
            $this->collapseDirectory();
        }
        return $this->workDom;
    }

Usage Example

Example #1
0
        /**
         * @return array
         */
        public function save() {
            $map = array('class' => 'classes', 'trait' => 'traits', 'interface' => 'interfaces');
            foreach ($map as $col) {
                $path = $this->xmlDir . '/' . $col;
                if (!file_exists($path)) {
                    mkdir($path, 0755, TRUE);
                }
            }
            $indexDom = $this->index->export();
            $reportUnits = $this->saveUnits;
            foreach($this->saveUnits as $unit) {
                /** @var AbstractUnitObject $unit  */
                $indexNode = $this->index->findUnitNodeByName($unit->getNamespace(), $unit->getLocalName());
                if (!$indexNode) {
                    throw new ProjectException(
                        sprintf(
                            "Internal Error: Unit '%s' not found in index (ns: %s, n: %s).",
                            $unit->getName(),
                            $unit->getNamespace(),
                            $unit->getLocalName()
                        ),
                        ProjectException::UnitNotFoundInIndex
                    );
                }
                $name = str_replace('\\', '_', $unit->getName());
                $dom = $unit->export();
                $dom->formatOutput = TRUE;
                $dom->preserveWhiteSpace = FALSE;
                $fname = $map[$dom->documentElement->localName] . '/' . $name . '.xml';
                if ($indexNode->hasAttribute('xml')) {
                     $reportUnits = array_merge($reportUnits, $this->findAffectedUnits($fname));
                } else {
                    $indexNode->setAttribute('xml', $fname);
                }
                $dom->save($this->xmlDir . '/' . $fname);
            }
            $indexDom->formatOutput = TRUE;
            $indexDom->preserveWhiteSpace = FALSE;
            $indexDom->save($this->xmlDir . '/index.xml');

            $sourceDom = $this->source->export();
            $sourceDom->formatOutput = TRUE;
            $sourceDom->preserveWhiteSpace = FALSE;
            $sourceDom->save($this->xmlDir . '/source.xml');

            $this->saveUnits = array();

            return $reportUnits;
        }
All Usage Examples Of TheSeer\phpDox\Collector\SourceCollection::export