-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
157 lines (118 loc) · 2.55 KB
/
test.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
function trace($var)
{
echo '<textarea style="width:900px;height:450px;">';
print_r($var);
echo '</textarea>';
exit;
}
trait Iwan
{
public final static function getInstans()
{
return App::getProvider(static::$provider);
}
public final static function __callStatic($name, $arguments)
{
$instans = static::getInstans();
return call_user_func_array(array($instans, $name), $arguments);
}
}
trait Extensible
{
protected static $methods = [];
protected static $staticMethods = [];
public final static function extend($name, $closure)
{
$o = new ReflectionObject($closure);
$m = $o->getMethod('__invoke');
if($m->isStatic())
{
static::$methods[$name] = Closure::bind($closure, null, get_class());
}
else
{
static::$staticMethods[$name] = Closure::bind($closure, $this, get_class());
}
//static::$methods[$name] = $closure->bindTo($this, get_class());
}
public final function __call($name, $args)
{
if(static::$methods[$name])
{
$closure = static::$methods[$name];
call_user_func($closure, $args);
}
}
public final static function __callStatic($name, $args)
{
if(static::$staticMethods[$name])
{
$closure = static::$staticMethods[$name];
return call_user_func_array($closure, $args);
}
}
}
class App
{
public static $providers = [];
public $version = 1.2;
public function __construct()
{
static::$providers['router'] = New Router;
static::$providers['app'] = $this;
}
public static function getProvider($name)
{
return static::$providers[$name];
}
public static function getInstans()
{
return static::$providers['app'];
}
}
class Router
{
use Extensible;
protected $name = 'dfdf';
protected static $a= 5454;
public function get($uri)
{
echo 'Router works! => '.$uri;
}
public static function post($uri)
{
echo 'Yes!, The static method works too!';
}
}
class Interfacer
{
}
class Route
{
use Iwan;
private static $provider = 'router';
}
$app = new Route;
//Route::get('555');
$i = 1;
Router::extend('put', static function($i)
{
echo $i++;
});
Router::extend('patch', function()
{
echo 'patch';
});
Router::put($i);
Router::put($i);
Router::put($i);
Router::put($i);
Router::put($i);
$f = function ()
{
};
var_dump(get_class($f));
//$r = new Router;
//$r->patch();
//Router::extend()