|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* KNUT7 K7F (https://marciozebedeu.com/) |
|
4
|
|
|
* KNUT7 K7F (tm) : Rapid Development Framework (https://marciozebedeu.com/) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under The MIT License |
|
7
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
8
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
9
|
|
|
* |
|
10
|
|
|
* @link https://github.com/knut7/framework/ for the canonical source repository |
|
11
|
|
|
* @copyright (c) 2015. KNUT7 Software Technologies AO Inc. (https://marciozebedeu.com/) |
|
12
|
|
|
* @license https://marciozebedeu.com/license/new-bsd New BSD License |
|
13
|
|
|
* @author Marcio Zebedeu - [email protected] |
|
14
|
|
|
* @version 1.0.2 |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
namespace Ballybran\Helpers\Utility; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
use ErrorException; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class ImportClass |
|
25
|
|
|
* Imports Pattern - Extend Classes in Real Time: |
|
26
|
|
|
* @package Ballybran\Helpers\Utility |
|
27
|
|
|
*/ |
|
28
|
|
|
class ImportClass |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
var $__imported; |
|
35
|
|
|
/** |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
var $__imported_functions; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* ImportClass constructor. |
|
42
|
|
|
*/ |
|
43
|
|
|
function __construct() |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$this->__imported = Array(); |
|
46
|
|
|
$this->__imported_functions = Array(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param $object |
|
51
|
|
|
*/ |
|
52
|
|
|
function Imports($object) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
$new_imports = $object; |
|
55
|
|
|
$imports_name = get_class($new_imports); |
|
56
|
|
|
array_push($this->__imported, Array($imports_name, $new_imports)); |
|
57
|
|
|
$imports_function = get_class_methods($new_imports); |
|
58
|
|
|
foreach ($imports_function as $i => $function_name) { |
|
59
|
|
|
$this->__imported_functions[$function_name] = &$new_imports; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param $method |
|
65
|
|
|
* @param $array |
|
66
|
|
|
* @return mixed |
|
67
|
|
|
* @throws ErrorException |
|
68
|
|
|
*/ |
|
69
|
|
|
function __call($method, $array) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
if (array_key_exists($method, $this->__imported_functions)) { |
|
72
|
|
|
return call_user_func_array(Array($this->__imported_functions[$method], $method), $array); |
|
73
|
|
|
} |
|
74
|
|
|
throw new ErrorException('Call to Undefined Method/Class Function', 0, E_ERROR); |
|
75
|
|
|
} |
|
76
|
|
|
} |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.