HashNode.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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>#<id>" 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 HashNode extends AbstractNode
  22. {
  23. private $selector;
  24. private $id;
  25. public function __construct(NodeInterface $selector, string $id)
  26. {
  27. $this->selector = $selector;
  28. $this->id = $id;
  29. }
  30. public function getSelector(): NodeInterface
  31. {
  32. return $this->selector;
  33. }
  34. public function getId(): string
  35. {
  36. return $this->id;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getSpecificity(): Specificity
  42. {
  43. return $this->selector->getSpecificity()->plus(new Specificity(1, 0, 0));
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function __toString(): string
  49. {
  50. return sprintf('%s[%s#%s]', $this->getNodeName(), $this->selector, $this->id);
  51. }
  52. }