Explorar o código

[CssSelector] renamed Parser::cssToXPath() to CssSelector::toXPath()

Fabien Potencier %!s(int64=14) %!d(string=hai) anos
pai
achega
af97610ee6

+ 4 - 4
src/Symfony/Component/CssSelector/Parser.php

@@ -14,10 +14,10 @@ namespace Symfony\Component\CssSelector;
 use Symfony\Component\CssSelector\Exception\ParseException;
 
 /**
- * Parser is the main entry point of the component and can convert CSS
+ * CssSelector is the main entry point of the component and can convert CSS
  * selectors to XPath expressions.
  *
- * $xpath = Parser::cssToXpath('h1.foo');
+ * $xpath = CssSelector::toXpath('h1.foo');
  *
  * This component is a port of the Python lxml library,
  * which is copyright Infrae and distributed under the BSD license.
@@ -26,7 +26,7 @@ use Symfony\Component\CssSelector\Exception\ParseException;
  *
  * @api
  */
-class Parser
+class CssSelector
 {
     /**
      * Translates a CSS expression to its XPath equivalent.
@@ -42,7 +42,7 @@ class Parser
      *
      * @api
      */
-    static public function cssToXpath($cssExpr, $prefix = 'descendant-or-self::')
+    static public function toXPath($cssExpr, $prefix = 'descendant-or-self::')
     {
         if (is_string($cssExpr)) {
             if (preg_match('#^\w+\s*$#u', $cssExpr, $match)) {

+ 3 - 3
src/Symfony/Component/DomCrawler/Crawler.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Component\DomCrawler;
 
-use Symfony\Component\CssSelector\Parser as CssParser;
+use Symfony\Component\CssSelector\CssSelector;
 
 /**
  * Crawler eases navigation of a list of \DOMNode objects.
@@ -503,13 +503,13 @@ class Crawler extends \SplObjectStorage
      */
     public function filter($selector)
     {
-        if (!class_exists('Symfony\\Component\\CssSelector\\Parser')) {
+        if (!class_exists('Symfony\\Component\\CssSelector\\CssSelector')) {
             // @codeCoverageIgnoreStart
             throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector is not installed (you can use filterXPath instead).');
             // @codeCoverageIgnoreEnd
         }
 
-        return $this->filterXPath(CssParser::cssToXpath($selector));
+        return $this->filterXPath(CssSelector::toXPath($selector));
     }
 
     /**

+ 10 - 10
tests/Symfony/Tests/Component/CssSelector/ParserTest.php

@@ -11,17 +11,17 @@
 
 namespace Symfony\Tests\Component\CssSelector;
 
-use Symfony\Component\CssSelector\Parser;
+use Symfony\Component\CssSelector\CssSelector;
 
-class ParserTest extends \PHPUnit_Framework_TestCase
+class CssSelectorTest extends \PHPUnit_Framework_TestCase
 {
-    public function testCssToXpath()
+    public function testCsstoXPath()
     {
-        $this->assertEquals('descendant-or-self::h1', Parser::cssToXpath('h1'));
-        $this->assertEquals("descendant-or-self::h1[@id = 'foo']", Parser::cssToXpath('h1#foo'));
-        $this->assertEquals("descendant-or-self::h1[contains(concat(' ', normalize-space(@class), ' '), ' foo ')]", Parser::cssToXpath('h1.foo'));
+        $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', Parser::cssToXpath('foo|h1'));
+        $this->assertEquals('descendant-or-self::foo:h1', CssSelector::toXPath('foo|h1'));
     }
 
     /**
@@ -29,14 +29,14 @@ class ParserTest extends \PHPUnit_Framework_TestCase
      */
     public function testParse($css, $xpath)
     {
-        $parser = new Parser();
+        $parser = new CssSelector();
 
-        $this->assertEquals($xpath, (string) $parser->parse($css)->toXpath(), '->parse() parses an input string and returns a node');
+        $this->assertEquals($xpath, (string) $parser->parse($css)->toXPath(), '->parse() parses an input string and returns a node');
     }
 
     public function testParseExceptions()
     {
-        $parser = new Parser();
+        $parser = new CssSelector();
 
         try {
             $parser->parse('h1:');