示例#1
0
 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());
 }
示例#2
0
        private function enrichByFile(fDOMDocument $dom) {
            $fileNode = $dom->queryOne('//phpdox:file');
            if (!$fileNode) {
                return;
            }

            $fileInfo = new FileInfo($fileNode->getAttribute('path'));
            $srcDir = $this->config->getSourceDirectory();
            $paths = explode('/', (string)$fileInfo->getRelative($srcDir));
            $file = $fileNode->getAttribute('file');
            $paths = array_slice($paths, 1);

            $query = sprintf('//pu:project/pu:directory[@name = "%s"]', $srcDir->getRealPath());
            foreach($paths as $path) {
                $query .= sprintf('/pu:directory[@name = "%s"]', $path);
            }
            $query .= sprintf('/pu:file[@name = "%s"]', $file);

            $phpunitFileNode = $this->index->queryOne($query);
            if (!$phpunitFileNode) {
                return;
            }

            $refDom = $this->loadXML($phpunitFileNode->getAttribute('href'));
            $this->processUnit($dom, $refDom);
        }
示例#3
0
 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);
 }
示例#5
0
 /**
  * @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;
 }
示例#6
0
 public function runConfigChangeDetection(FileInfo $workDirectory, FileInfo $configFile)
 {
     $index = new FileInfo((string) $workDirectory . '/index.xml');
     if (!$index->exists() || $index->getMTime() >= $configFile->getMTime()) {
         return;
     }
     $this->logger->log("Configuration change detected - cleaning cache");
     $cleaner = $this->factory->getDirectoryCleaner();
     $cleaner->process($workDirectory);
 }
示例#7
0
 /**
  * @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;
 }
示例#8
0
 /**
  * @param fDOMDocument $dom
  *
  * @return fDOMDocument
  *
  * @throws EnricherException
  * @throws PHPUnitEnricherException
  */
 private function loadCoverageInformation(fDOMDocument $dom)
 {
     $fileNode = $dom->queryOne('//phpdox:file');
     if (!$fileNode) {
         throw new PHPUnitEnricherException('No file header in event dom');
     }
     $fileInfo = new FileInfo($fileNode->getAttribute('path'));
     $srcDir = $this->getSourceDirectory();
     $paths = explode('/', (string) $fileInfo->getRelative($srcDir));
     $file = $fileNode->getAttribute('file');
     $paths = array_slice($paths, 1);
     $query = sprintf('//pu:project/pu:directory[@name = "%s"]', $srcDir->getRealPath());
     foreach ($paths as $path) {
         $query .= sprintf('/pu:directory[@name = "%s"]', $path);
     }
     $query .= sprintf('/pu:file[@name = "%s"]', $file);
     $phpunitFileNode = $this->index->queryOne($query);
     if (!$phpunitFileNode) {
         throw new PHPUnitEnricherException('No coverage information for file');
     }
     $refDom = $this->loadXML($phpunitFileNode->getAttribute('href'));
     return $refDom;
 }
示例#9
0
 /**
  * @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);
     }
 }
示例#10
0
 public function __construct($file_name, FileInfo $srcDir = NULL, $encoding = 'auto')
 {
     parent::__construct($file_name);
     $this->srcDir = $srcDir;
     $this->encoding = $encoding;
 }
示例#11
0
 public function removeFile(FileInfo $file)
 {
     $relPath = (string) $file->getRelative($this->srcDir);
     unset($this->collection[$relPath]);
 }
示例#12
0
文件: CLI.php 项目: sakshika/ATM
 /**
  * Main executor for CLI process.
  */
 public function run()
 {
     $errorHandler = $this->factory->getInstanceFor('ErrorHandler');
     $errorHandler->register();
     try {
         $this->preBootstrap();
         $options = $this->processOptions();
         if ($options->getValue('version') === TRUE) {
             $this->showVersion();
             exit(0);
         }
         if ($options->getValue('skel') === TRUE) {
             $this->showSkeletonConfig($options->getValue('strip'));
             exit(0);
         }
         if ($options->getValue('help') === TRUE) {
             $this->showVersion();
             $this->showUsage();
             exit(0);
         }
         $cfgLoader = $this->factory->getInstanceFor('ConfigLoader');
         $cfgFile = $options->getValue('file');
         if ($cfgFile) {
             $config = $cfgLoader->load($cfgFile);
         } else {
             $config = $cfgLoader->autodetect();
         }
         /** @var $config GlobalConfig */
         if ($config->isSilentMode()) {
             $this->factory->setLoggerType('silent');
         } else {
             $this->showVersion();
             $this->factory->setLoggerType('shell');
         }
         $logger = $this->factory->getInstanceFor('Logger');
         $logger->log("Using config file '" . $config->getConfigFile()->getPathname() . "'");
         /** @var Application $app */
         $app = $this->factory->getInstanceFor('Application');
         $bootstrap = $app->runBootstrap(array(new FileInfo(__DIR__ . '/../bootstrap/backends.php'), new FileInfo(__DIR__ . '/../bootstrap/enrichers.php'), new FileInfo(__DIR__ . '/../bootstrap/engines.php')));
         $bootstrap->load($config->getBootstrapFiles(), false);
         if ($options->getValue('engines')) {
             $this->showVersion();
             $this->showList('engines', $bootstrap->getEngines());
             exit(0);
         }
         if ($options->getValue('enrichers')) {
             $this->showVersion();
             $this->showList('enrichers', $bootstrap->getEnrichers());
             exit(0);
         }
         if ($options->getValue('backends')) {
             $this->showVersion();
             $this->showList('backends', $bootstrap->getBackends());
             exit(0);
         }
         foreach ($config->getAvailableProjects() as $project) {
             $logger->log("Starting to process project '{$project}'");
             $pcfg = $config->getProjectConfig($project);
             $index = new FileInfo($pcfg->getWorkDirectory() . '/index.xml');
             if ($index->exists() && $index->getMTime() < $config->getConfigFile()->getMTime()) {
                 $logger->log("Configuration change detected - cleaning cache");
                 $cleaner = new DirectoryCleaner();
                 $cleaner->process(new FileInfo($pcfg->getWorkDirectory()));
             }
             if (!$options->getValue('generator')) {
                 $app->runCollector($pcfg->getCollectorConfig());
             }
             if (!$options->getValue('collector')) {
                 $app->runGenerator($pcfg->getGeneratorConfig());
             }
             $logger->log("Processing project '{$project}' completed.");
         }
         $logger->buildSummary();
     } catch (CLIEnvironmentException $e) {
         $this->showVersion();
         fwrite(STDERR, 'Sorry, but your PHP environment is currently not able to run phpDox due to');
         fwrite(STDERR, "\nthe following issue(s):\n\n" . $e->getMessage() . "\n\n");
         fwrite(STDERR, "Please adjust your PHP configuration and try again.\n\n");
         exit(3);
     } catch (CLIOptionsException $e) {
         $this->showVersion();
         fwrite(STDERR, "\n" . $e->getMessage() . "\n\n");
         $this->showUsage();
         exit(3);
     } catch (ConfigLoaderException $e) {
         $this->showVersion();
         fwrite(STDERR, "\nAn error occured while trying to load the configuration file:\n\t" . $e->getMessage() . "\n\nUsing --skel might get you started.\n\n");
         exit(3);
     } catch (ConfigException $e) {
         fwrite(STDERR, "\nYour configuration seems to be corrupted:\n\n\t" . $e->getMessage() . "\n\nPlease verify your configuration xml file.\n\n");
         exit(3);
     } catch (ApplicationException $e) {
         fwrite(STDERR, "\nAn application error occured while processing:\n\n\t" . $e->getMessage() . "\n\nPlease verify your configuration.\n\n");
         exit(1);
     } catch (\Exception $e) {
         if ($e instanceof fDOMException) {
             $e->toggleFullMessage(TRUE);
         }
         $this->showVersion();
         $errorHandler->handleException($e);
     }
 }
示例#13
0
文件: Project.php 项目: sakshika/ATM
 /**
  * @param FileInfo $file
  */
 public function removeFile(FileInfo $file)
 {
     $this->removeFileReferences($file->getPathname());
     $this->source->removeFile($file);
 }
示例#14
0
 /**
  * @return string
  */
 public function render()
 {
     return file_get_contents($this->file->getPathname());
 }
示例#15
0
 public function __construct($file_name, FileInfo $srcDir = NULL)
 {
     parent::__construct($file_name);
     $this->srcDir = $srcDir;
 }
示例#16
0
        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;
        }
示例#17
0
 /**
  * @param $path
  * @return \DOMNodeList
  */
 public function findUnitNodesBySrcFile($path) {
     $search = new FileInfo($path);
     return $this->getRootElement()->query(sprintf('//*[@src="%s"]', $search->getRelative($this->srcDir)));
 }