Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\CssSelector\Node; Chris@0: Chris@0: use Symfony\Component\CssSelector\Parser\Token; Chris@0: Chris@0: /** Chris@0: * Represents a ":()" node. Chris@0: * Chris@0: * This component is a port of the Python cssselect library, Chris@0: * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect. Chris@0: * Chris@0: * @author Jean-François Simon Chris@0: * Chris@0: * @internal Chris@0: */ Chris@0: class FunctionNode extends AbstractNode Chris@0: { Chris@0: private $selector; Chris@0: private $name; Chris@0: private $arguments; Chris@0: Chris@0: /** Chris@0: * @param NodeInterface $selector Chris@0: * @param string $name Chris@0: * @param Token[] $arguments Chris@0: */ Chris@17: public function __construct(NodeInterface $selector, $name, array $arguments = []) Chris@0: { Chris@0: $this->selector = $selector; Chris@0: $this->name = strtolower($name); Chris@0: $this->arguments = $arguments; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return NodeInterface Chris@0: */ Chris@0: public function getSelector() Chris@0: { Chris@0: return $this->selector; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return $this->name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return Token[] Chris@0: */ Chris@0: public function getArguments() Chris@0: { Chris@0: return $this->arguments; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getSpecificity() Chris@0: { Chris@0: return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function __toString() Chris@0: { Chris@0: $arguments = implode(', ', array_map(function (Token $token) { Chris@0: return "'".$token->getValue()."'"; Chris@0: }, $this->arguments)); Chris@0: Chris@0: return sprintf('%s[%s:%s(%s)]', $this->getNodeName(), $this->selector, $this->name, $arguments ? '['.$arguments.']' : ''); Chris@0: } Chris@0: }