Example #1
0
 public function testExcludePrefixes()
 {
     $config = new Config();
     $this->assertFalse($config->shouldExcludeResultPrefixes());
     $config->excludeResultPrefixes();
     $this->assertTrue($config->shouldExcludeResultPrefixes());
 }
Example #2
0
 public function testMethod()
 {
     $extension = new MyExtension();
     $config = new Config();
     $config->addExtension($extension);
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/method.xsl');
     $xslDoc->documentElement->setAttribute('version', '1.0');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/collection.xml');
     $processor = new XsltProcessor($config);
     $processor->importStylesheet($xslDoc);
     $processorResult = $processor->transformToXML($xmlDoc);
     $this->assertEquals('24', trim($processorResult));
 }
Example #3
0
 /**
  * @param Transpiler $transpiler
  * @return array
  */
 private function createStreamOptions(Transpiler $transpiler)
 {
     $contextOptions = ['gxsl' => ['transpiler' => $transpiler]];
     try {
         $contextOptions['gxsl']['cache'] = $this->config->getCacheAdapter();
     } catch (CacheDisabledException $e) {
         // caching adapter is not required for the processor to run
     }
     return $contextOptions;
 }
Example #4
0
 public function testCache()
 {
     $arrayCache = new ArrayAdapter();
     $config = new Config();
     $config->setCacheAdapter(new SimpleCallbackAdapter($arrayCache));
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/combine-multiple-functions.xsl');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/combine-multiple-functions.xml');
     $processor = new XsltProcessor($config);
     $processor->importStylesheet($xslDoc);
     $processorResult = $processor->transformToXML($xmlDoc);
     $cacheKey = dirname(__DIR__) . '/Stubs/combine-multiple-functions.xsl';
     $cache = $arrayCache->get($cacheKey);
     $this->assertEquals(157, trim($processorResult));
     $this->assertNotNull($cache);
     $cache = str_replace('floor', 'ceiling', $cache);
     $arrayCache->set($cacheKey, $cache);
     $this->assertEquals(158, trim($processor->transformToXML($xmlDoc)));
 }
Example #5
0
 /**
  * @param DOMDocument $document
  */
 public function transform(DOMDocument $document)
 {
     $root = $document->documentElement;
     $namespaces = FetchNamespacesFromNode::fetch($document->documentElement);
     $xslPrefix = array_search(XslTransformations::URI, $namespaces);
     $excludePrefixes = preg_split('/\\s/', $root->getAttribute('exclude-result-prefixes'));
     $excludePrefixes[] = 'php';
     $excludePrefixes[] = 'xs';
     if (in_array('#all', $excludePrefixes) === true || $this->config->shouldExcludeResultPrefixes()) {
         $excludePrefixes = array_merge($excludePrefixes, array_keys($namespaces));
         $excludePrefixes = array_filter($excludePrefixes, function ($prefix) {
             return $prefix !== '#all';
         });
     }
     $excludePrefixes = array_unique($excludePrefixes);
     $root->setAttribute('xmlns:php', 'http://php.net/xsl');
     $root->setAttribute('xmlns:xs', XmlSchema::URI);
     $root->setAttribute('exclude-result-prefixes', implode(' ', $excludePrefixes));
     $this->transformElements($document, $xslPrefix);
     $this->transformAttributes($document, $xslPrefix);
 }
Example #6
0
 /**
  * @param Xpath\Compiler $xpathCompiler
  * @return XmlNamespaceInterface[]
  */
 private function getNamespaces($xpathCompiler)
 {
     $namespaces = [new Xsl\XslTransformations($xpathCompiler, $this->config), new Xpath\XmlPath(), new Schema\XmlSchema()];
     return array_merge($namespaces, $this->config->getExtensions());
 }
Example #7
0
 public function testSetExtensions()
 {
     $config = new Config();
     $config->setExtensions([new XmlSchema()]);
     $this->assertContainsOnlyInstancesOf(XmlSchema::class, $config->getExtensions());
 }