Drupal investigation

ElementNode.php 1.6KB

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