CombinedSelectorNode.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 NodeInterface $selector
  28. * @param string $combinator
  29. * @param NodeInterface $subSelector
  30. */
  31. public function __construct(NodeInterface $selector, $combinator, NodeInterface $subSelector)
  32. {
  33. $this->selector = $selector;
  34. $this->combinator = $combinator;
  35. $this->subSelector = $subSelector;
  36. }
  37. /**
  38. * @return NodeInterface
  39. */
  40. public function getSelector()
  41. {
  42. return $this->selector;
  43. }
  44. /**
  45. * @return string
  46. */
  47. public function getCombinator()
  48. {
  49. return $this->combinator;
  50. }
  51. /**
  52. * @return NodeInterface
  53. */
  54. public function getSubSelector()
  55. {
  56. return $this->subSelector;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function getSpecificity()
  62. {
  63. return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function __toString()
  69. {
  70. $combinator = ' ' === $this->combinator ? '<followed>' : $this->combinator;
  71. return sprintf('%s[%s %s %s]', $this->getNodeName(), $this->selector, $combinator, $this->subSelector);
  72. }
  73. }