OrNode.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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. use Symfony\Component\CssSelector\XPathExprOr;
  12. /**
  13. * OrNode represents a "Or" node.
  14. *
  15. * This component is a port of the Python lxml library,
  16. * which is copyright Infrae and distributed under the BSD license.
  17. *
  18. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  19. */
  20. class OrNode implements NodeInterface
  21. {
  22. protected $items;
  23. /**
  24. * Constructor.
  25. *
  26. * @param array $items An array of NodeInterface objects
  27. */
  28. public function __construct($items)
  29. {
  30. $this->items = $items;
  31. }
  32. /**
  33. * {@inheritDoc}
  34. */
  35. public function __toString()
  36. {
  37. return sprintf('%s(%s)', __CLASS__, $this->items);
  38. }
  39. /**
  40. * {@inheritDoc}
  41. */
  42. public function toXpath()
  43. {
  44. $paths = array();
  45. foreach ($this->items as $item) {
  46. $paths[] = $item->toXpath();
  47. }
  48. return new XPathExprOr($paths);
  49. }
  50. }