123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
- namespace Gogs\API\Request {
- /**
- * Collection is a collection of data of one type.
- *
- * @see Users
- * @author Joachim M. Giaever (joachim[]giaever.org)
- * @version 0.1.3
- */
- abstract class Collection extends Base implements \Gogs\Lib\ArrayIterator {
- private $objs;
-
- public function __construct(string $api_url, string $api_token, Collection $other = null) {
- parent::__construct($api_url, $api_token);
- if ($other != null)
- $this->objs = $others->copy();
- else
- $this->objs = new \Gogs\Lib\Collection();
- }
-
- protected function add($obj, $key = null) {
- $this->objs->set($obj, $key);
- return $key == null ? $this->objs->len() - 1 : $key;
- }
-
- protected function remove($any, bool $deep = true) {
- return $objs->remove($any, $deep);
- }
-
- public function copy() {
- return new Collection($this);
- }
-
- public function all() {
- return $this->objs->copy()->all();
- }
-
- public function len() {
- return $this->objs->len();
- }
-
- public function by_key($idx) {
- return $this->objs->by_key($idx);
- }
-
- public function next() {
- return $this->objs->next();
- }
-
- public function prev() {
- return $this->objs->prev();
- }
-
- public function current() {
- return $this->objs->current();
- }
-
- public function reset() {
- return $this->objs->reset();
- }
-
- public function sort(callable $f) {
- return $this->objs->copy()->sort($f);
- }
-
- public function filter(callable $f) {
- return $this->objs->copy()->filter($f);
- }
-
- public function limit(int $lim) {
- return $this->objs->copy()->limit($lim);
- }
-
- public function offset(int $off) {
- return $this->objs->copy()->offset($off);
- }
-
- public function reverse() {
- return $this->objs->copy()->reverse();
- }
-
- protected function json_set_property(\stdClass $obj) {
- $keys = array();
- if (!is_object($obj) && !is_array($obj))
- return array();
- if (isset($obj->data))
- return $this->json_set_property((object)$obj->data);
- foreach($obj as $key => $val)
- $keys[] = $this->add_object($val);
- return $keys;
- }
-
- public function search(array $params = array(), bool $strict = false) {
- throw new NotImplementedException("::search:: Not implemented by class '" . get_class($this) . "'");
- }
-
- abstract protected function add_object(\stdClass $object);
-
- abstract public function sort_by(int $flag = \Gogs\Lib\ArrayIterator::SORT_INDEX);
- }
- }
- ?>
|