This repository has been archived by the owner on Jan 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
/
obj.php
107 lines (82 loc) · 1.76 KB
/
obj.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
// direct access protection
if(!defined('KIRBY')) die('Direct access is not allowed');
/**
* The Core Object
*
* Almost every other object in Kirby is based
* on this class and their methods.
*
* It implements magic getters, setters,
* helper methods and a custom iterator.
*
* @package Kirby CMS
*/
class obj implements Iterator {
public $_ = array();
function __construct($array=array()) {
$this->_ = $array;
}
function __set($n, $v) {
$this->_[$n] = $v;
}
function __get($n) {
return a::get($this->_, $n);
}
function __call($n, $args) {
return a::get($this->_, strtolower($n));
}
function rewind() {
reset($this->_);
}
function current() {
return current($this->_);
}
function key() {
return key($this->_);
}
function next() {
return next($this->_);
}
function prev() {
return prev($this->_);
}
function nth($n) {
$array = array_values($this->_);
return (isset($array[$n])) ? $array[$n] : false;
}
function valid() {
$key = key($this->_);
$var = ($key !== NULL && $key !== FALSE);
return $var;
}
function find() {
$args = func_get_args();
$key = @$args[0];
$default = @$args[1];
if(!$key) return $this->_;
return a::get($this->_, $key, $default);
}
function count() {
return count($this->_);
}
function first() {
return a::first($this->_);
}
function last() {
return a::last($this->_);
}
function indexOf($needle) {
foreach(array_values($this->_) as $key => $value) {
if($value === $needle) return $key;
}
return false;
}
function shuffle() {
$this->_ = a::shuffle($this->_);
return $this;
}
function toArray() {
return $this->_;
}
}