Bez popisu

ClassNode.php 1.5KB

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