XPathExprOr.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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;
  11. /**
  12. * XPathExprOr represents XPath |'d expressions.
  13. *
  14. * Note that unfortunately it isn't the union, it's the sum, so duplicate elements will appear.
  15. *
  16. * This component is a port of the Python lxml library,
  17. * which is copyright Infrae and distributed under the BSD license.
  18. *
  19. * @author Fabien Potencier <fabien@symfony.com>
  20. */
  21. class XPathExprOr extends XPathExpr
  22. {
  23. /**
  24. * Constructor.
  25. *
  26. * @param array $items The items in the expression.
  27. * @param string $prefix Optional prefix for the expression.
  28. */
  29. public function __construct($items, $prefix = null)
  30. {
  31. $this->items = $items;
  32. $this->prefix = $prefix;
  33. }
  34. /**
  35. * Gets a string representation of this |'d expression.
  36. *
  37. * @return string
  38. */
  39. public function __toString()
  40. {
  41. $prefix = $this->getPrefix();
  42. $tmp = array();
  43. foreach ($this->items as $i) {
  44. $tmp[] = sprintf('%s%s', $prefix, $i);
  45. }
  46. return implode($tmp, ' | ');
  47. }
  48. }