菜谱项目

SelectorNode.php 1.6KB

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