Collection.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Gogs\API\Request {
  3. abstract class Collection extends Base implements \Gogs\Lib\ArrayIterator {
  4. private $objs = array();
  5. public function add($obj, $key = null) {
  6. if (!isset($key))
  7. array_push($this->objs, $obj);
  8. else
  9. $this->objs[$key] = $obj;
  10. }
  11. public function remove($any) {
  12. if (isset($this->objs[$any])) {
  13. unset($this->objs[$any]);
  14. return true;
  15. } else if (in_array($any, $this->objs)) {
  16. $key = array_search($any, $this->objs, true);
  17. return $this->remove($key);
  18. }
  19. return false;
  20. }
  21. public function all() {
  22. return $this->objs;
  23. }
  24. public function len() {
  25. return count($this->objs);
  26. }
  27. public function by_key($idx) {
  28. return isset($this->objs[$idx]) ? $this->objs[$idx] : false;
  29. }
  30. public function next() {
  31. return next($this->objs);
  32. }
  33. public function prev() {
  34. return prev($this->objs);
  35. }
  36. public function current() {
  37. return current($this->objs);
  38. }
  39. public function reset() {
  40. return reset($this->objs);
  41. }
  42. //abstract public function create(...$args);
  43. abstract public function search(array $params = array());
  44. }
  45. }
  46. ?>