PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.8.1
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.8.1
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Support / Facade.php

Facade.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.8.1, at vendor/wpfluent/framework/src/WPFluent/Support/Facade.php

150 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Framework\Support;
4
5 use Closure;
6 use RuntimeException;
7
8 abstract class Facade
9 {
10 /**
11 * The application instance being facaded.
12 *
13 * @var \FluentCommunity\Framework\Foundation\Application
14 */
15 protected static $app;
16
17 /**
18 * The resolved object instances.
19 *
20 * @var array
21 */
22 protected static $resolvedInstance;
23
24 /**
25 * Run a Closure when the facade has been resolved.
26 *
27 * @param \Closure $callback
28 * @return void
29 */
30 public static function resolved(Closure $callback)
31 {
32 $accessor = static::getFacadeAccessor();
33
34 if (static::$app->resolved($accessor) === true) {
35 $callback(static::getFacadeRoot());
36 }
37
38 static::$app->afterResolving($accessor, function ($service) use ($callback) {
39 $callback($service);
40 });
41 }
42
43 /**
44 * Get the root object behind the facade.
45 *
46 * @return mixed
47 */
48 public static function getFacadeRoot()
49 {
50 return static::resolveFacadeInstance(static::getFacadeAccessor());
51 }
52
53 /**
54 * Get the registered name of the component.
55 *
56 * @return string
57 *
58 * @throws \RuntimeException
59 */
60 protected static function getFacadeAccessor()
61 {
62 throw new RuntimeException(
63 'Facade does not implement getFacadeAccessor method.'
64 );
65 }
66
67 /**
68 * Resolve the facade root instance from the container.
69 *
70 * @param object|string $name
71 * @return mixed
72 */
73 protected static function resolveFacadeInstance($name)
74 {
75 if (is_object($name)) {
76 return $name;
77 }
78
79 if (isset(static::$resolvedInstance[$name])) {
80 return static::$resolvedInstance[$name];
81 }
82
83 if (static::$app) {
84 return static::$resolvedInstance[$name] = static::$app[$name];
85 }
86 }
87
88 /**
89 * Clear a resolved facade instance.
90 *
91 * @param string $name
92 * @return void
93 */
94 public static function clearResolvedInstance($name)
95 {
96 unset(static::$resolvedInstance[$name]);
97 }
98
99 /**
100 * Clear all of the resolved instances.
101 *
102 * @return void
103 */
104 public static function clearResolvedInstances()
105 {
106 static::$resolvedInstance = [];
107 }
108
109 /**
110 * Get the application instance behind the facade.
111 *
112 * @return \FluentCommunity\Framework\Foundation\Application
113 */
114 public static function getFacadeApplication()
115 {
116 return static::$app;
117 }
118
119 /**
120 * Set the application instance.
121 *
122 * @param \FluentCommunity\Framework\Foundation\Application $app
123 * @return void
124 */
125 public static function setFacadeApplication($app)
126 {
127 static::$app = $app;
128 }
129
130 /**
131 * Handle dynamic, static calls to the object.
132 *
133 * @param string $method
134 * @param array $args
135 * @return mixed
136 *
137 * @throws \RuntimeException
138 */
139 public static function __callStatic($method, $args)
140 {
141 $instance = static::getFacadeRoot();
142
143 if (! $instance) {
144 throw new RuntimeException('A facade root has not been set.');
145 }
146
147 return $instance->$method(...$args);
148 }
149 }
150