-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstaticaccess.php
90 lines (72 loc) · 1.83 KB
/
staticaccess.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
<?php
/**
* StaticAccess Class for PHP OOP
* Creator: Yalçın CEYLAN
* Github: http://github.com/yali4/
* Website: http://yalcinceylan.net
* License: MIT <http://opensource.org/licenses/mit-license.php>
*/
class StaticAccess {
/**
* Örneği döndürmek için.
*
* @return mixed
*/
public static function getInstance()
{
if ( static::$instance )
{
return static::$instance;
}
return static::$instance = new static();
}
/**
* Örnek üzerinden erişimler.
*
* @param $method
* @param array $args
* @return mixed
*/
private static function callMethod($method, array $args)
{
$instance = self::getInstance();
$method = 'static'.ucfirst($method);
switch( count($args) )
{
case 0:
return $instance->$method();
case 1:
return $instance->$method($args[0]);
case 2:
return $instance->$method($args[0], $args[1]);
case 3:
return $instance->$method($args[0], $args[1], $args[2]);
case 4:
return $instance->$method($args[0], $args[1], $args[2], $args[3]);
default:
return call_user_func_array(array($instance, $method), $args);
}
}
/**
* Normal çağrılar için.
*
* @param $method
* @param $arguments
* @return mixed
*/
public function __call($method, $arguments)
{
return self::callMethod($method, $arguments);
}
/**
* Statik çağrılar için.
*
* @param $method
* @param $arguments
* @return mixed
*/
public static function __callStatic($method, $arguments)
{
return self::callMethod($method, $arguments);
}
}