NegationNode.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "<selector>:not(<identifier>)" 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 NegationNode extends AbstractNode
  22. {
  23. private $selector;
  24. private $subSelector;
  25. public function __construct(NodeInterface $selector, NodeInterface $subSelector)
  26. {
  27. $this->selector = $selector;
  28. $this->subSelector = $subSelector;
  29. }
  30. /**
  31. * @return NodeInterface
  32. */
  33. public function getSelector()
  34. {
  35. return $this->selector;
  36. }
  37. /**
  38. * @return NodeInterface
  39. */
  40. public function getSubSelector()
  41. {
  42. return $this->subSelector;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function getSpecificity(): Specificity
  48. {
  49. return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function __toString(): string
  55. {
  56. return sprintf('%s[%s:not(%s)]', $this->getNodeName(), $this->selector, $this->subSelector);
  57. }
  58. }