ElementNode.php 1.5 KB

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