Pull merge.
[yaffs-website] / vendor / symfony / css-selector / Node / FunctionNode.php
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\Parser\Token;
15
16 /**
17  * Represents a "<selector>:<name>(<arguments>)" node.
18  *
19  * This component is a port of the Python cssselect library,
20  * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
21  *
22  * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
23  *
24  * @internal
25  */
26 class FunctionNode extends AbstractNode
27 {
28     private $selector;
29     private $name;
30     private $arguments;
31
32     /**
33      * @param NodeInterface $selector
34      * @param string        $name
35      * @param Token[]       $arguments
36      */
37     public function __construct(NodeInterface $selector, $name, array $arguments = array())
38     {
39         $this->selector = $selector;
40         $this->name = strtolower($name);
41         $this->arguments = $arguments;
42     }
43
44     /**
45      * @return NodeInterface
46      */
47     public function getSelector()
48     {
49         return $this->selector;
50     }
51
52     /**
53      * @return string
54      */
55     public function getName()
56     {
57         return $this->name;
58     }
59
60     /**
61      * @return Token[]
62      */
63     public function getArguments()
64     {
65         return $this->arguments;
66     }
67
68     /**
69      * {@inheritdoc}
70      */
71     public function getSpecificity()
72     {
73         return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
74     }
75
76     /**
77      * {@inheritdoc}
78      */
79     public function __toString()
80     {
81         $arguments = implode(', ', array_map(function (Token $token) {
82             return "'".$token->getValue()."'";
83         }, $this->arguments));
84
85         return sprintf('%s[%s:%s(%s)]', $this->getNodeName(), $this->selector, $this->name, $arguments ? '['.$arguments.']' : '');
86     }
87 }