当前位置: 首页>>代码示例>>PHP>>正文


PHP CssSelector\CssSelector类代码示例

本文整理汇总了PHP中Symfony\Component\CssSelector\CssSelector的典型用法代码示例。如果您正苦于以下问题:PHP CssSelector类的具体用法?PHP CssSelector怎么用?PHP CssSelector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CssSelector类的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: testParseExceptions

 public function testParseExceptions()
 {
     $parser = new CssSelector();
     try {
         $parser->parse('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 symbol, got '' at h1: -> ", $e->getMessage(), '->parse() throws an Exception if the css selector is not valid');
     }
 }
开发者ID:laubosslink,项目名称:lab,代码行数:11,代码来源:CssSelectorTest.php

示例3: 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

示例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: 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

示例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: testPageIsSuccessful

 /**
  * @dataProvider provideUrls
  * @param $url
  */
 public function testPageIsSuccessful($url)
 {
     $client = static::createClient();
     CssSelector::disableHtmlExtension();
     $crawler = $client->request('GET', $url);
     $this->assertTrue($client->getResponse()->isSuccessful());
     $this->assertGreaterThan(0, $crawler->filter('pre:contains("ck>Success</")')->count());
 }
开发者ID:iBasit,项目名称:EbayApiBundle,代码行数:12,代码来源:CallControllerTest.php

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例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: parseCrawler

 /**
  * @param Crawler $crawler
  *
  * @return \JakubZapletal\Component\BankStatement\Statement\Statement
  */
 protected function parseCrawler(Crawler $crawler)
 {
     $this->statement = $this->getStatementClass();
     CssSelector::disableHtmlExtension();
     $crawler = $crawler->filter('FINSTA > FINSTA03');
     if ($crawler !== null) {
         $this->parseStatementNode($crawler);
         $parser = $this;
         $crawler->filter('FINSTA05')->each(function (Crawler $node) use($parser) {
             $parser->parseAndAddTransaction($node);
         });
     }
     return $this->statement;
 }
开发者ID:jakubzapletal,项目名称:bank-statements,代码行数:19,代码来源:CSOBCZParser.php


注:本文中的Symfony\Component\CssSelector\CssSelector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。