CombinedSelectorNode.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. public function __construct(
  24. private NodeInterface $selector,
  25. private string $combinator,
  26. private NodeInterface $subSelector,
  27. ) {
  28. }
  29. public function getSelector(): NodeInterface
  30. {
  31. return $this->selector;
  32. }
  33. public function getCombinator(): string
  34. {
  35. return $this->combinator;
  36. }
  37. public function getSubSelector(): NodeInterface
  38. {
  39. return $this->subSelector;
  40. }
  41. public function getSpecificity(): Specificity
  42. {
  43. return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
  44. }
  45. public function __toString(): string
  46. {
  47. $combinator = ' ' === $this->combinator ? '<followed>' : $this->combinator;
  48. return \sprintf('%s[%s %s %s]', $this->getNodeName(), $this->selector, $combinator, $this->subSelector);
  49. }
  50. }