private function initDomDocument() { $this->dom = new fDOMDocument('1.0', 'UTF-8'); $this->dom->registerNamespace('phpdox', 'http://xml.phpdox.net/src'); $index = $this->dom->appendElementNS('http://xml.phpdox.net/src', 'index'); $index->setAttribute('basedir', $this->srcDir->getRealPath()); }
public function export() { 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(); return $this->workDom; }
/** * @param $ctx * * @return mixed * @throws ConfigException */ protected function runResolver($ctx) { if (defined('PHPDOX_HOME')) { $home = PHPDOX_HOME; } else { $home = realpath(__DIR__ . '/../../'); } $vars = array('basedir' => $ctx->getAttribute('basedir', dirname($this->file->getRealPath())), 'phpDox.home' => $home, 'phpDox.file' => $this->file->getPathname(), 'phpDox.version' => Version::getVersion(), 'phpDox.project.name' => $ctx->getAttribute('name', 'unnamed'), 'phpDox.project.source' => $ctx->getAttribute('source', 'src'), 'phpDox.project.workdir' => $ctx->getAttribute('workdir', 'xml'), 'phpDox.php.version' => PHP_VERSION); $protected = array_keys($vars); foreach ($ctx->query('cfg:property|/cfg:phpdox/cfg:property') as $property) { /** @var $property \DOMElement */ $name = $property->getAttribute('name'); $line = $property->getLineNo(); if (in_array($name, $protected)) { throw new ConfigException("Cannot overwrite system property in line {$line}", ConfigException::OverrideNotAllowed); } if (isset($vars[$name])) { throw new ConfigException("Cannot overwrite existing property '{$name}' in line {$line}", ConfigException::OverrideNotAllowed); } $vars[$name] = $this->resolveValue($property->getAttribute('value'), $vars, $line); } foreach ($ctx->query('.//*[not(name()="property")]/@*|@*') as $attr) { $attr->nodeValue = $this->resolveValue($attr->nodeValue, $vars, $attr->getLineNo()); } return $ctx; }