vendor/symfony/src/Symfony/Component/CssSelector/Node/ClassNode.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Symfony\Component\CssSelector\Node;
       
    13 
       
    14 use Symfony\Component\CssSelector\XPathExpr;
       
    15 
       
    16 /**
       
    17  * ClassNode represents a "selector.className" node.
       
    18  *
       
    19  * This component is a port of the Python lxml library,
       
    20  * which is copyright Infrae and distributed under the BSD license.
       
    21  *
       
    22  * @author Fabien Potencier <fabien@symfony.com>
       
    23  */
       
    24 class ClassNode implements NodeInterface
       
    25 {
       
    26     protected $selector;
       
    27     protected $className;
       
    28 
       
    29     /**
       
    30      * The constructor.
       
    31      *
       
    32      * @param NodeInterface $selector The XPath Selector
       
    33      * @param string $className The class name
       
    34      */
       
    35     public function __construct($selector, $className)
       
    36     {
       
    37         $this->selector = $selector;
       
    38         $this->className = $className;
       
    39     }
       
    40 
       
    41     /**
       
    42      * {@inheritDoc}
       
    43      */
       
    44     public function __toString()
       
    45     {
       
    46         return sprintf('%s[%s.%s]', __CLASS__, $this->selector, $this->className);
       
    47     }
       
    48 
       
    49     /**
       
    50      * {@inheritDoc}
       
    51      */
       
    52     public function toXpath()
       
    53     {
       
    54         $selXpath = $this->selector->toXpath();
       
    55         $selXpath->addCondition(sprintf("contains(concat(' ', normalize-space(@class), ' '), %s)", XPathExpr::xpathLiteral(' '.$this->className.' ')));
       
    56 
       
    57         return $selXpath;
       
    58     }
       
    59 }