SelectorNode.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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>(::|:)<pseudoElement>" 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 SelectorNode extends AbstractNode
  22. {
  23. private $tree;
  24. private $pseudoElement;
  25. /**
  26. * @param string|null $pseudoElement
  27. */
  28. public function __construct(NodeInterface $tree, $pseudoElement = null)
  29. {
  30. $this->tree = $tree;
  31. $this->pseudoElement = $pseudoElement ? strtolower($pseudoElement) : null;
  32. }
  33. /**
  34. * @return NodeInterface
  35. */
  36. public function getTree()
  37. {
  38. return $this->tree;
  39. }
  40. /**
  41. * @return string|null
  42. */
  43. public function getPseudoElement()
  44. {
  45. return $this->pseudoElement;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function getSpecificity()
  51. {
  52. return $this->tree->getSpecificity()->plus(new Specificity(0, 0, $this->pseudoElement ? 1 : 0));
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function __toString()
  58. {
  59. return sprintf('%s[%s%s]', $this->getNodeName(), $this->tree, $this->pseudoElement ? '::'.$this->pseudoElement : '');
  60. }
  61. }