|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* KNUT7 K7F (https://marciozebedeu.com/) |
|
5
|
|
|
* KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/) |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under The MIT License |
|
8
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
10
|
|
|
* |
|
11
|
|
|
* @link https://github.com/knut7/framework/ for the canonical source repository |
|
12
|
|
|
* @copyright (c) 2015. KNUT7 Software Technologies AO Inc. (https://marciozebedeu.com/) |
|
13
|
|
|
* @license https://marciozebedeu.com/license/new-bsd New BSD License |
|
14
|
|
|
* @author Marcio Zebedeu - [email protected] |
|
15
|
|
|
* @version 1.0.2 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
namespace Ballybran\Core\Variables; |
|
20
|
|
|
|
|
21
|
|
|
use ArrayObject; |
|
22
|
|
|
|
|
23
|
|
|
class Variable extends ArrayObject |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
private $___class = null; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct(array $variables = array()) |
|
29
|
|
|
{ |
|
30
|
|
|
parent::__construct( |
|
31
|
|
|
$variables, ArrayObject::ARRAY_AS_PROPS, 'ArrayIterator' |
|
32
|
|
|
); |
|
33
|
|
|
$this->importObj($variables); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function __get($key) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this[$key]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function __set($key, $value) |
|
42
|
|
|
{ |
|
43
|
|
|
$this[$key] = $value; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function __call($key, $args) |
|
47
|
|
|
{ |
|
48
|
|
|
if (is_object($this->___class) && is_callable([$this->___class, $key])) { |
|
49
|
|
|
return call_user_func_array([$this->___class, $key], $args); |
|
50
|
|
|
} |
|
51
|
|
|
return is_callable($c = $this->__get($key)) ? call_user_func_array($c, $args) : null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function importObj($class = null, $array = []) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->___class = $class; |
|
57
|
|
|
if (count($array) > 0) { |
|
58
|
|
|
$this->import($array); |
|
59
|
|
|
} |
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function import(array $input) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->exchangeArray($input); |
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function export() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->objectToArray($this->getArrayCopy()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function objectToArray($object) |
|
75
|
|
|
{ |
|
76
|
|
|
$o = []; |
|
77
|
|
|
foreach ($object as $key => $value) { |
|
78
|
|
|
$o[$key] = is_object($value) ? (array)$value : $value; |
|
79
|
|
|
} |
|
80
|
|
|
return $o; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|