PropertyPathIterator.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\PropertyAccess;
  11. /**
  12. * Traverses a property path and provides additional methods to find out
  13. * information about the current element.
  14. *
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. */
  17. class PropertyPathIterator extends \ArrayIterator implements PropertyPathIteratorInterface
  18. {
  19. /**
  20. * The traversed property path.
  21. *
  22. * @var PropertyPathInterface
  23. */
  24. protected $path;
  25. /**
  26. * Constructor.
  27. *
  28. * @param PropertyPathInterface $path The property path to traverse
  29. */
  30. public function __construct(PropertyPathInterface $path)
  31. {
  32. parent::__construct($path->getElements());
  33. $this->path = $path;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function isIndex()
  39. {
  40. return $this->path->isIndex($this->key());
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function isProperty()
  46. {
  47. return $this->path->isProperty($this->key());
  48. }
  49. }