예제 #1
0
파일: Query.php 프로젝트: elazar/zend-dom
 /**
  * Perform the query on Document
  *
  * @param  string    $expression CSS selector or XPath query
  * @param  Document  $document   Document to query
  * @param  string    $type       The type of $expression
  * @return NodeList
  */
 public static function execute($expression, Document $document, $type = self::TYPE_XPATH)
 {
     // Expression check
     if ($type === static::TYPE_CSS) {
         $expression = static::cssToXpath($expression);
     }
     $xpath = new DOMXPath($document->getDomDocument());
     $xpathNamespaces = $document->getXpathNamespaces();
     foreach ($xpathNamespaces as $prefix => $namespaceUri) {
         $xpath->registerNamespace($prefix, $namespaceUri);
     }
     if ($xpathPhpfunctions = $document->getXpathPhpFunctions()) {
         $xpath->registerNamespace('php', 'http://php.net/xpath');
         $xpathPhpfunctions === true ? $xpath->registerPHPFunctions() : $xpath->registerPHPFunctions($xpathPhpfunctions);
     }
     $nodeList = $xpath->queryWithErrorException($expression);
     return new NodeList($nodeList);
 }
예제 #2
0
 public function testDom()
 {
     // Gerenciador de Serviços
     $serviceManager = Application::getApplication()->getServiceManager();
     // Resolução de Scripts
     $resolver = new TemplateMapResolver(['error/404' => './module/Balance/view/error/404.phtml', 'layout/page-header' => './module/Balance/view/layout/page-header.phtml']);
     // Renderização
     $renderer = (new PhpRenderer())->setResolver($resolver);
     // Configurar Serviço
     $renderer->getHelperPluginManager()->setServiceLocator($serviceManager);
     // Camada de Visualização
     $view = (new ViewModel())->setTemplate('error/404');
     // Configurar Controladora
     $view->setVariable('controller', 'FooController');
     // Renderização
     $content = $renderer->render($view);
     // Apresentar Estrutura
     $document = new Document($content);
     // Capturar DOM
     $document->getDomDocument();
     // Validação
     $this->assertEmpty($document->getErrors(), 'Invalid Document Structure');
 }
예제 #3
0
 public function testgetDomMethodShouldReturnDomDocumentWithStringDocumentInConstructor()
 {
     $html = $this->getHtml();
     $document = new Document($html);
     $this->assertTrue($document->getDomDocument() instanceof \DOMDocument);
 }