Drupal investigation

FunctionNode.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\CssSelector\Node;
  11. use Symfony\Component\CssSelector\Parser\Token;
  12. /**
  13. * Represents a "<selector>:<name>(<arguments>)" node.
  14. *
  15. * This component is a port of the Python cssselect library,
  16. * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
  17. *
  18. * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
  19. *
  20. * @internal
  21. */
  22. class FunctionNode extends AbstractNode
  23. {
  24. /**
  25. * @var NodeInterface
  26. */
  27. private $selector;
  28. /**
  29. * @var string
  30. */
  31. private $name;
  32. /**
  33. * @var Token[]
  34. */
  35. private $arguments;
  36. /**
  37. * @param NodeInterface $selector
  38. * @param string $name
  39. * @param Token[] $arguments
  40. */
  41. public function __construct(NodeInterface $selector, $name, array $arguments = array())
  42. {
  43. $this->selector = $selector;
  44. $this->name = strtolower($name);
  45. $this->arguments = $arguments;
  46. }
  47. /**
  48. * @return NodeInterface
  49. */
  50. public function getSelector()
  51. {
  52. return $this->selector;
  53. }
  54. /**
  55. * @return string
  56. */
  57. public function getName()
  58. {
  59. return $this->name;
  60. }
  61. /**
  62. * @return Token[]
  63. */
  64. public function getArguments()
  65. {
  66. return $this->arguments;
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function getSpecificity()
  72. {
  73. return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function __toString()
  79. {
  80. $arguments = implode(', ', array_map(function (Token $token) {
  81. return "'".$token->getValue()."'";
  82. }, $this->arguments));
  83. return sprintf('%s[%s:%s(%s)]', $this->getNodeName(), $this->selector, $this->name, $arguments ? '['.$arguments.']' : '');
  84. }
  85. }