Example #1
0
 private function getCacheDom()
 {
     if ($this->cacheDom === NULL) {
         $this->cacheDom = new fDOMDocument();
         $cacheFile = $this->config->getLogfilePath();
         if (file_exists($cacheFile)) {
             $this->cacheDom->load($cacheFile);
             $sha1 = $this->cacheDom->documentElement->getAttribute('sha1');
             $cwd = getcwd();
             chdir($this->config->getSourceDirectory());
             exec($this->config->getGitBinary() . ' diff --name-only ' . $sha1, $files, $rc);
             foreach ($files as $file) {
                 $fields = array('path' => dirname($file), 'file' => basename($file));
                 $query = $this->cacheDom->prepareQuery('//*[@path = :path and @file = :file]', $fields);
                 $node = $this->cacheDom->queryOne($query);
                 if (!$node) {
                     continue;
                 }
                 $node->parentNode->removeChild($node);
             }
             chdir($cwd);
         } else {
             $this->cacheDom->loadXML('<?xml version="1.0" ?><gitlog xmlns="' . self::GITNS . '" />');
             $this->cacheDom->documentElement->setAttribute('sha1', $this->commitSha1);
         }
     }
     return $this->cacheDom;
 }
Example #2
0
 /**
  * @param string[] $units
  * @param string[] $visibilities
  * @return fDOMDocument
  */
 private function createPhpDoxConfig(array $units, array $visibilities)
 {
     $dom = new fDOMDocument();
     $dom->loadXML($this->factory->getConfigSkeleton()->renderStripped());
     $dom->registerNamespace('config', ConfigLoader::XMLNS);
     // set up silent
     $silent = $this->output->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL ? 'true' : 'false';
     $dom->queryOne('//config:phpdox')->setAttribute('silent', $silent);
     // set up directories
     $projectNode = $dom->queryOne('//config:project');
     $projectNode->setAttribute('source', $this->sourceDirectory);
     $projectNode->setAttribute('workdir', $this->buildDirectory);
     // inject flag to avoid unecessary processing according to the visibility filter
     if (1 === count($visibilities) && in_array('public', $visibilities)) {
         $collectorNode = $dom->queryOne('//config:collector');
         $projectNode->setAttribute('publiconly', 'true');
     }
     // remove current masks
     $query = "//config:collector/*[name()='include' or name()='exclude']";
     foreach ($dom->query($query) as $mask) {
         $mask->parentNode->removeChild($mask);
     }
     // append files to be parsed
     $collector = $dom->queryOne('//config:collector');
     foreach ($units as $unitFile) {
         $include = $dom->createElement('include');
         $include->setAttribute('mask', $unitFile);
         $collector->appendChild($include);
     }
     return $dom;
 }
Example #3
0
 /**
  * https://github.com/theseer/fDOMDocument/issues/15
  */
 public function testQueryReturnsNodeFromClonedDocument()
 {
     $this->dom->loadXML('<?xml version="1.0" ?><test />');
     $clone = clone $this->dom;
     $node = $clone->queryOne('/test');
     $this->assertNotSame($this->dom->documentElement, $node);
 }
Example #4
0
 public function testGetChildrenByTagnameNSReturnsCorrectNodelist()
 {
     $this->dom->loadXML('<?xml version="1.0" ?><root xmlns="test:uri"><node><child/></node><node /></root>');
     $this->node = $this->dom->documentElement;
     $list = $this->node->getChildrenByTagNameNS('test:uri', 'node');
     $this->assertInstanceOf('DOMNodeList', $list);
     $this->assertEquals(2, $list->length);
 }
Example #5
0
 /**
  * @return string
  */
 public function renderStripped()
 {
     $dom = new fDOMDocument();
     $dom->preserveWhiteSpace = FALSE;
     $dom->loadXML(preg_replace("/\\s{2,}/u", " ", $this->render()));
     foreach ($dom->query('//comment()') as $c) {
         $c->parentNode->removeChild($c);
     }
     $dom->formatOutput = TRUE;
     return $dom->saveXML();
 }
Example #6
0
 /**
  * @param string $source
  *
  * @return fDOMDocument
  *
  * @throws \TheSeer\fDOM\fDOMException
  */
 public function toXML($source)
 {
     $this->writer = new \XMLWriter();
     $this->writer->openMemory();
     $this->writer->setIndent(true);
     $this->writer->startDocument();
     $this->writer->startElement('source');
     $this->writer->writeAttribute('xmlns', 'http://xml.phpdox.net/token');
     $this->writer->startElement('line');
     $this->writer->writeAttribute('no', 1);
     $this->lastLine = 1;
     $tokens = token_get_all($source);
     foreach ($tokens as $pos => $tok) {
         if (is_string($tok)) {
             $line = 1;
             $step = 1;
             while (!is_array($tokens[$pos - $step])) {
                 $step++;
                 if ($pos - $step == -1) {
                     break;
                 }
             }
             if ($pos - $step != -1) {
                 $line = $tokens[$pos - $step][2];
                 $line += count(preg_split('/\\R+/', $tokens[$pos - $step][1])) - 1;
             }
             $token = array('name' => $this->map[$tok], 'value' => $tok, 'line' => $line);
             $this->addToken($token);
         } else {
             $line = $tok[2];
             $values = preg_split('/\\R+/Uu', $tok[1]);
             foreach ($values as $v) {
                 $token = array('name' => token_name($tok[0]), 'value' => $v, 'line' => $line);
                 $this->addToken($token);
                 $line++;
             }
         }
     }
     $this->writer->endElement();
     $this->writer->endElement();
     $this->writer->endDocument();
     $dom = new fDOMDocument();
     $dom->preserveWhiteSpace = false;
     $dom->loadXML($this->writer->outputMemory());
     return $dom;
 }
Example #7
0
 private function showSkeletonConfig($strip)
 {
     $config = file_get_contents(__DIR__ . '/config/skeleton.xml');
     if ($strip) {
         $config = preg_replace("/\\s{2,}/u", " ", $config);
         $dom = new fDOMDocument();
         $dom->preserveWhiteSpace = FALSE;
         $dom->loadXML($config);
         foreach ($dom->query('//comment()') as $c) {
             $c->parentNode->removeChild($c);
         }
         $dom->formatOutput = TRUE;
         $config = $dom->saveXML();
     }
     echo $config;
 }
Example #8
0
 public function setUp()
 {
     $this->dom = new fDOMDocument();
     $this->dom->loadXML('<?xml version="1.0" ?><root><node attr="foo" /></root>');
     $this->xp = $this->dom->getDOMXPath();
 }