CombinedSelectorNode.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /**
  12. * Represents a combined node.
  13. *
  14. * This component is a port of the Python cssselect library,
  15. * which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
  16. *
  17. * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
  18. *
  19. * @internal
  20. */
  21. class CombinedSelectorNode extends AbstractNode
  22. {
  23. private $selector;
  24. private $combinator;
  25. private $subSelector;
  26. /**
  27. * @param string $combinator
  28. */
  29. public function __construct(NodeInterface $selector, $combinator, NodeInterface $subSelector)
  30. {
  31. $this->selector = $selector;
  32. $this->combinator = $combinator;
  33. $this->subSelector = $subSelector;
  34. }
  35. /**
  36. * @return NodeInterface
  37. */
  38. public function getSelector()
  39. {
  40. return $this->selector;
  41. }
  42. /**
  43. * @return string
  44. */
  45. public function getCombinator()
  46. {
  47. return $this->combinator;
  48. }
  49. /**
  50. * @return NodeInterface
  51. */
  52. public function getSubSelector()
  53. {
  54. return $this->subSelector;
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function getSpecificity()
  60. {
  61. return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function __toString()
  67. {
  68. $combinator = ' ' === $this->combinator ? '<followed>' : $this->combinator;
  69. return sprintf('%s[%s %s %s]', $this->getNodeName(), $this->selector, $combinator, $this->subSelector);
  70. }
  71. }