arraywrapper.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('STATUSNET') && !defined('LACONICA')) {
  20. exit(1);
  21. }
  22. class ArrayWrapper
  23. {
  24. var $_items = null;
  25. var $_count = 0;
  26. var $N = 0;
  27. var $_i = -1;
  28. function __construct($items)
  29. {
  30. $this->_items = $items;
  31. $this->_count = count($this->_items);
  32. $this->N = $this->_count;
  33. }
  34. function fetch()
  35. {
  36. if (!$this->_items) {
  37. return false;
  38. }
  39. $this->_i++;
  40. if ($this->_i < $this->_count) {
  41. return true;
  42. } else {
  43. return false;
  44. }
  45. }
  46. function fetchAll($k= false, $v = false, $method = false)
  47. {
  48. if ($k !== false || $v !== false || $method !== false)
  49. {
  50. $item =& $this->_items[$this->_i];
  51. return $item->fetchAll($k, $v, $method);
  52. }
  53. return $this->_items;
  54. }
  55. function __set($name, $value)
  56. {
  57. $item =& $this->_items[$this->_i];
  58. $item->$name = $value;
  59. return $item->$name;
  60. }
  61. function __get($name)
  62. {
  63. $item =& $this->_items[$this->_i];
  64. return $item->$name;
  65. }
  66. function __isset($name)
  67. {
  68. $item =& $this->_items[$this->_i];
  69. return isset($item->$name);
  70. }
  71. function __unset($name)
  72. {
  73. $item =& $this->_items[$this->_i];
  74. unset($item->$name);
  75. }
  76. function __call($name, $args)
  77. {
  78. $item =& $this->_items[$this->_i];
  79. if (!is_object($item)) {
  80. common_log(LOG_ERR, "Invalid entry " . var_export($item, true) . " at index $this->_i of $this->N; calling $name()");
  81. throw new ServerException("Internal error: bad entry in array wrapper list.");
  82. }
  83. return call_user_func_array(array($item, $name), $args);
  84. }
  85. }