public function asDom() { if (!$this->dom instanceof fDOMDocument) { $this->dom = new fDOMDocument(); $this->dom->load($this->file->getPathname()); $this->dom->registerNamespace('phpdox', SourceFile::XMLNS); } return $this->dom; }
private function init($cfgName) { $this->version = new Version('0.0'); $this->fileInfo = new FileInfo($this->baseDir . $cfgName . '.xml'); $this->cfgDom = new fDOMDocument(); $this->cfgDom->load($this->fileInfo->getPathname()); $this->cfgDom->registerNamespace('cfg', 'http://xml.phpdox.net/config'); $this->config = new GlobalConfig($this->version, new FileInfo('/tmp'), $this->cfgDom, $this->fileInfo); }
/** * @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; }
public function addFile(FileInfo $file) { $node = $this->workDom->createElementNS('http://xml.phpdox.net/src#', 'file'); $node->setAttribute('name', basename($file->getBasename())); $node->setAttribute('size', $file->getSize()); $node->setAttribute('time', date('c', $file->getMTime())); $node->setAttribute('unixtime', $file->getMTime()); $node->setAttribute('sha1', sha1_file($file->getPathname())); $path = $file->getRealPath(); $this->collection[$path] = $node; return $this->isChanged($path); }
/** * @return string * * @throws Backend\SourceFileException */ public function getSource() { $code = file_get_contents($this->fileInfo->getPathname()); $info = new \finfo(); $encoding = $info->file($this->fileInfo, FILEINFO_MIME_ENCODING); if (strtolower($encoding) != 'utf-8') { try { $code = iconv($encoding, 'UTF-8//TRANSLIT', $code); } catch (\ErrorException $e) { throw new SourceFileException('Encoding error - conversion to UTF-8 failed', SourceFileException::BadEncoding, $e); } } // This is a workaround to filter out leftover invalid UTF-8 byte sets // even if the source looks like it's UTF-8 already mb_substitute_character('none'); $cleanCode = mb_convert_encoding($code, 'UTF-8', 'UTF-8'); if ($cleanCode != $code) { throw new SourceFileException('Encoding error - invalid UTF-8 bytes found', SourceFileException::InvalidDataBytes); } return $cleanCode; }
/** * @param FileInfo $file */ private function processFile(FileInfo $file) { try { if ($file->getSize() === 0) { $this->logger->progress('processed'); return true; } $result = $this->backend->parse(new SourceFile($file)); if ($result->hasClasses()) { foreach ($result->getClasses() as $class) { $this->project->addClass($class); } } if ($result->hasInterfaces()) { foreach ($result->getInterfaces() as $interface) { $this->project->addInterface($interface); } } if ($result->hasTraits()) { foreach ($result->getTraits() as $trait) { $this->project->addTrait($trait); } } $this->logger->progress('processed'); return true; } catch (ParseErrorException $e) { $this->parseErrors[$file->getPathname()] = $e->getPrevious()->getMessage(); $this->logger->progress('failed'); return false; } catch (\Exception $e) { throw new CollectorException('Error while processing source file', CollectorException::ProcessingError, $e, $file); } }
/** * @param FileInfo $file */ public function removeFile(FileInfo $file) { $this->removeFileReferences($file->getPathname()); $this->source->removeFile($file); }
/** * @return string */ public function render() { return file_get_contents($this->file->getPathname()); }