123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php namespace Client\Request;
- class SearchParamException extends \Exception {};
- abstract class Collection extends Base implements \Lib\ArrayIterator {
- private $objs = array();
- public function add($obj, $key = null) {
- if ($obj == false)
- echo "OBJ ($key) = FALSE\n";
- if (!isset($key))
- array_push($this->objs, $obj);
- else
- $this->objs[$key] = $obj;
- }
- public function remove($any) {
- if (isset($this->objs[$any])) {
- unset($this->objs[$any]);
- return true;
- } else if (in_array($any, $this->objs)) {
- $key = array_search($any, $this->objs, true);
- return $this->remove($key);
- }
- return false;
- }
- public function all() {
- return $this->objs;
- }
- public function len() {
- return $this->objs;
- }
- public function by_key($idx) {
- return isset($this->objs[$idx]) ? $this->objs[$idx] : false;
- }
- public function next() {
- return next($this->objs);
- }
- public function prev() {
- return prev($this->objs);
- }
- public function current() {
- return current($this->objs);
- }
- public function reset() {
- return reset($this->objs);
- }
- //abstract public function create(...$args);
- abstract public function search(array $params = array());
- }
- class CollectionResult implements \Lib\ArrayIterator {
- private $objs = array();
- public function set($val, $key = null) {
- if ($key == null && is_array($val))
- $this->objs = $val;
- else if ($key != null)
- $this->objs[$key] = $val;
- else
- array_push($this->objs, $val);
- }
- public function by_key($idx) {
- return isset($this->objs[$idx]) ? $this->objs[$idx] : false;
- }
- public function all() {
- return $this->objs;
- }
- public function len() {
- return count($this->objs);
- }
- public function next() {
- return next($this->objs);
- }
- public function current() {
- return current($this->objs);
- }
- public function reset() {
- return current($this->objs);
- }
- }
- ?>
|