Page.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * A representation of a page of resources.
  4. *
  5. * @category Services
  6. * @package Services_Twilio
  7. * @author Neuman Vong <neuman@twilio.com>
  8. * @license http://creativecommons.org/licenses/MIT/ MIT
  9. * @link http://pear.php.net/package/Services_Twilio
  10. */
  11. class Services_Twilio_Page
  12. implements IteratorAggregate
  13. {
  14. /**
  15. * The item list.
  16. *
  17. * @var array $items
  18. */
  19. protected $items;
  20. /**
  21. * Constructs a page.
  22. *
  23. * @param object $page The page object
  24. * @param string $name The key of the item list
  25. */
  26. public function __construct($page, $name, $next_page_uri = null)
  27. {
  28. $this->page = $page;
  29. $this->items = $page->{$name};
  30. $this->next_page_uri = $next_page_uri;
  31. }
  32. /**
  33. * The item list of the page.
  34. *
  35. * @return array A list of instance resources
  36. */
  37. public function getItems()
  38. {
  39. return $this->items;
  40. }
  41. /**
  42. * Magic method to allow retrieving the properties of the wrapped page.
  43. *
  44. * @param string $prop The property name
  45. *
  46. * @return mixed Could be anything
  47. */
  48. public function __get($prop)
  49. {
  50. return $this->page->$prop;
  51. }
  52. /**
  53. * Implementation of IteratorAggregate::getIterator().
  54. *
  55. * @return Traversable
  56. */
  57. public function getIterator()
  58. {
  59. return $this->getItems();
  60. }
  61. }