You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

3 years ago
  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. public function __construct(NodeInterface $tree, string $pseudoElement = null)
  26. {
  27. $this->tree = $tree;
  28. $this->pseudoElement = $pseudoElement ? strtolower($pseudoElement) : null;
  29. }
  30. public function getTree(): NodeInterface
  31. {
  32. return $this->tree;
  33. }
  34. public function getPseudoElement(): ?string
  35. {
  36. return $this->pseudoElement;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getSpecificity(): Specificity
  42. {
  43. return $this->tree->getSpecificity()->plus(new Specificity(0, 0, $this->pseudoElement ? 1 : 0));
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function __toString(): string
  49. {
  50. return sprintf('%s[%s%s]', $this->getNodeName(), $this->tree, $this->pseudoElement ? '::'.$this->pseudoElement : '');
  51. }
  52. }