-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacade.php
62 lines (55 loc) · 1.38 KB
/
facade.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
<?php
require_once __DIR__ . '/model.php';
class User extends Facade
{
protected static function getFacadeAccessor()
{
$instanceKey = 'user';
if (!isset(self::$resolvedInstance[$instanceKey])) {
$user = new Model\TestModel\User();
self::$resolvedInstance[$instanceKey] = $user;
}
return $instanceKey;
}
}
/**
* A simple Facade Class, From Illuminate\Support\Facades\Facade
*/
abstract class Facade
{
/**
* The resolved object instances.
*
* @var array
*/
protected static $resolvedInstance;
/**
* Get the registered name of the component.
*
* @return string
*
* @throws \RuntimeException
*/
protected static function getFacadeAccessor()
{
throw new RuntimeException('Facade does not implement getFacadeAccessor method.');
}
/**
* Handle dynamic, static calls to the object.
*
* @param string $method
* @param array $args
* @return mixed
*
* @throws \RuntimeException
*/
public static function __callStatic($method, $args)
{
$instanceKey = static::getFacadeAccessor();
$instance = self::$resolvedInstance[$instanceKey];
if (! $instance) {
throw new RuntimeException('A facade root has not been set.');
}
return $instance->$method(...$args);
}
}