SpecificityAdjustmentNode.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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>:where(<subSelectorList>)" 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 Hubert Lenoir <lenoir.hubert@gmail.com>
  18. *
  19. * @internal
  20. */
  21. class SpecificityAdjustmentNode extends AbstractNode
  22. {
  23. /**
  24. * @param array<NodeInterface> $arguments
  25. */
  26. public function __construct(
  27. public readonly NodeInterface $selector,
  28. public readonly array $arguments = [],
  29. ) {
  30. }
  31. public function getSpecificity(): Specificity
  32. {
  33. return $this->selector->getSpecificity();
  34. }
  35. public function __toString(): string
  36. {
  37. $selectorArguments = array_map(
  38. fn ($n) => ltrim((string) $n, '*'),
  39. $this->arguments,
  40. );
  41. return \sprintf('%s[%s:where(%s)]', $this->getNodeName(), $this->selector, implode(', ', $selectorArguments));
  42. }
  43. }