當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CssSelector::toXPath方法代碼示例

本文整理匯總了PHP中Symfony\Component\CssSelector\CssSelector::toXPath方法的典型用法代碼示例。如果您正苦於以下問題:PHP CssSelector::toXPath方法的具體用法?PHP CssSelector::toXPath怎麽用?PHP CssSelector::toXPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\CssSelector\CssSelector的用法示例。


在下文中一共展示了CssSelector::toXPath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: translateToXPath

 /**
  * Translates CSS into XPath.
  *
  * @param string|array $locator current selector locator
  *
  * @return string
  */
 public function translateToXPath($locator)
 {
     if (!is_string($locator)) {
         throw new \InvalidArgumentException('The CssSelector expects to get a string as locator');
     }
     // Symfony 2.8+ API
     if (class_exists('Symfony\\Component\\CssSelector\\CssSelectorConverter')) {
         $converter = new CssSelectorConverter();
         return $converter->toXPath($locator);
     }
     // old static API for Symfony 2.7 and older
     return CSS::toXPath($locator);
 }
開發者ID:joelpittet,項目名稱:Mink,代碼行數:20,代碼來源:CssSelector.php

示例2: testBlender

 public function testBlender()
 {
     $inputDir = __DIR__ . '/../../ressources/input';
     $outputDir = __DIR__ . '/../../ressources/output';
     $this->process->blend($inputDir, $outputDir);
     $exiftoolBinary = __DIR__ . '/../../../vendor/alchemy/exiftool/exiftool';
     $metas = array('NomdelaPhoto' => array('src' => 'IPTC:Headline', 'value' => 'hello'), 'Rubrique' => array('src' => 'IPTC:Category', 'value' => 'salut'), 'MotsCles' => array('src' => 'IPTC:Keywords', 'value' => 'kakoo'), 'DatedeParution' => array('src' => 'IPTC:Source', 'value' => '2012/04/13'), 'DatePrisedeVue' => array('src' => 'IPTC:DateCreated', 'value' => '2012:04:13'), 'Ville' => array('src' => 'IPTC:City', 'value' => 'paris'), 'Pays' => array('src' => 'IPTC:Country-PrimaryLocationName', 'value' => 'france'), 'Copyright' => array('src' => 'IPTC:CopyrightNotice', 'value' => 'yata'));
     $cmd = $exiftoolBinary . ' -X ' . __DIR__ . '/../../ressources/output/1.jpg';
     $output = shell_exec($cmd);
     if ($output) {
         $document = new \DOMDocument();
         $document->loadXML($output);
         $xpath = new \DOMXPath($document);
         $xPathQuery = CssSelector::toXPath('*');
         foreach ($metas as $metaInfo) {
             $found = false;
             foreach ($xpath->query($xPathQuery) as $node) {
                 $nodeName = $node->nodeName;
                 $value = $node->nodeValue;
                 if ($nodeName == $metaInfo['src']) {
                     $this->assertEquals($value, $metaInfo['value']);
                     $found = true;
                     continue;
                 }
             }
             if (!$found) {
                 $this->fail('missing ' . $metaInfo['src']);
             }
         }
     }
 }
開發者ID:nlegoff,項目名稱:Blender,代碼行數:31,代碼來源:WriteMetasFromXMLTest.php

示例3: translateToXPath

 /**
  * Translates CSS into XPath.
  *
  * @param string|array $locator current selector locator
  *
  * @return string
  */
 public function translateToXPath($locator)
 {
     if (!is_string($locator)) {
         throw new \InvalidArgumentException('The CssSelector expects to get a string as locator');
     }
     return CSS::toXPath($locator);
 }
開發者ID:ddrozdik,項目名稱:dmaps,代碼行數:14,代碼來源:CssSelector.php

示例4: query

 /**
  * Return DOMNodeList from CSS selector
  *
  * @param $string
  * @return \DOMNodeList
  */
 public function query($string)
 {
     CssSelector::disableHtmlExtension();
     $xpathQuery = CssSelector::toXPath($string);
     $xpath = new \DOMXPath($this->data);
     return $xpath->query($xpathQuery);
 }
開發者ID:ajbdev,項目名稱:scraper,代碼行數:13,代碼來源:XmlParser.php

示例5: testCsstoXPath

 public function testCsstoXPath()
 {
     $this->assertEquals('descendant-or-self::h1', CssSelector::toXPath('h1'));
     $this->assertEquals("descendant-or-self::h1[@id = 'foo']", CssSelector::toXPath('h1#foo'));
     $this->assertEquals("descendant-or-self::h1[contains(concat(' ', normalize-space(@class), ' '), ' foo ')]", CssSelector::toXPath('h1.foo'));
     $this->assertEquals('descendant-or-self::foo:h1', CssSelector::toXPath('foo|h1'));
 }
開發者ID:robertowest,項目名稱:CuteFlow-V4,代碼行數:7,代碼來源:CssSelectorTest.php

示例6: updateXPathExpression

 /**
  * Create and update XPath expression
  */
 public function updateXPathExpression()
 {
     if ($this->type === 'css') {
         $this->xpath_expression = CssSelector::toXPath($this->selector);
     } else {
         $this->xpath_expression = $this->selector;
     }
 }
開發者ID:toflar,項目名稱:contao-css-class-replacer,代碼行數:11,代碼來源:RuleModel.php

示例7: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $selector = $input->getArgument('selector');
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $block = $formatter->formatBlock(CssSelector::toXPath($selector), 'question', true);
     $output->writeln($block);
 }
開發者ID:GrizliK1988,項目名稱:symfony-certification-prepare-project,代碼行數:8,代碼來源:CssSelectorTestCommand.php

示例8: isCSS

 /**
  * @param $selector
  * @return bool
  */
 public static function isCSS($selector)
 {
     try {
         CssSelector::toXPath($selector);
     } catch (ParseException $e) {
         return false;
     }
     return true;
 }
開發者ID:zrashwani,項目名稱:news-scrapper,代碼行數:13,代碼來源:Selector.php

示例9: html

 public function html()
 {
     $ref = clone $this->_doc;
     $xpath = new DOMXPath($ref);
     foreach ($xpath->query(CssSelector::toXPath('*[data-domref]')) as $node) {
         $node->removeAttribute('data-domref');
     }
     return $ref->saveHTML();
 }
開發者ID:boltphp,項目名稱:core,代碼行數:9,代碼來源:dom.php

示例10: toXPath

 protected static function toXPath($selector)
 {
     try {
         $xpath = CssSelector::toXPath($selector);
     } catch (\Symfony\Component\CssSelector\Exception\ParseException $e) {
         $xpath = $selector;
     }
     return $xpath;
 }
開發者ID:pfz,項目名稱:codeception,代碼行數:9,代碼來源:Locator.php

示例11: assertRows

 /**
  * Ensures that the rendered results are working as expected.
  *
  * @param array $expected
  *   The expected rows of the result.
  */
 protected function assertRows($expected = [])
 {
     $actual = [];
     $rows = $this->cssSelect('div.views-row');
     foreach ($rows as $row) {
         $actual[] = ['title' => (string) $row->xpath(CssSelector::toXPath('.views-field-title span.field-content a'))[0], 'sticky' => (string) $row->xpath(CssSelector::toXPath('.views-field-sticky span.field-content'))[0]];
     }
     $this->assertEqual($actual, $expected);
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:15,代碼來源:FieldEntityTranslationTest.php

示例12: testParseExceptions

 public function testParseExceptions()
 {
     try {
         CssSelector::toXPath('h1:');
         $this->fail('->parse() throws an Exception if the css selector is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Symfony\\Component\\CssSelector\\Exception\\ParseException', $e, '->parse() throws an Exception if the css selector is not valid');
         $this->assertEquals("Expected identifier, but <eof at 3> found.", $e->getMessage(), '->parse() throws an Exception if the css selector is not valid');
     }
 }
開發者ID:mawaha,項目名稱:tracker,代碼行數:10,代碼來源:CssSelectorTest.php

示例13: toXPath

 /**
  * Metodo que convierte un selector css en un xpath
  * @param  string $css_selector Cadena de texto con el selector css.
  * @return string|NULL          Devuelve una cadena de texto con formato xpath si la converción e sposible o NULL en caso contrario.
  */
 private function toXPath($css_selector)
 {
     $xpath = Null;
     try {
         $xpath = $this->selector->toXPath($css_selector);
     } catch (\Exception $e) {
         $this->logger->logError('E003', array($css_selector));
         $this->logger->logError('E000', array($e->getMessage()));
     }
     return $xpath;
 }
開發者ID:elmijo,項目名稱:php-html-dom,代碼行數:16,代碼來源:PHPHtmlDom.php

示例14: matches

 /**
  * Evaluates the constraint for parameter $other. Returns true if the
  * constraint is met, false otherwise.
  *
  * @param  mixed $other
  * @return bool
  */
 public function matches($other)
 {
     if ($other instanceof DOMElement) {
         $xpathSelector = CssSelector::toXPath($this->cssSelector, '//');
         $xpath = new DOMXPath($other->ownerDocument);
         foreach ($xpath->query($xpathSelector) as $node) {
             if ($node === $other) {
                 return true;
             }
         }
     }
     return false;
 }
開發者ID:spiderling-php,項目名稱:phpunit-matches-selector,代碼行數:20,代碼來源:MatchesSelector.php

示例15: toXPath

 public function toXPath()
 {
     try {
         if (class_exists('Symfony\\Component\\CssSelector\\CssSelectorConverter')) {
             $converter = new CssSelectorConverter();
             $query = $converter->toXPath($this->selector);
         } else {
             $query = CssSelector::toXPath($this->selector);
         }
     } catch (ExceptionInterface $e) {
         $query = null;
     }
     return $query;
 }
開發者ID:heruujoko,項目名稱:tsel-net-management,代碼行數:14,代碼來源:Selector.php


注:本文中的Symfony\Component\CssSelector\CssSelector::toXPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。