PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.0
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / vendor / wpfluent / framework / src / WPFluent / Support / Facade.php

Facade.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.0, at vendor/wpfluent/framework/src/WPFluent/Support/Facade.php

148 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 FluentBooking\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 \FluentBooking\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('Facade does not implement getFacadeAccessor method.');
63 }
64
65 /**
66 * Resolve the facade root instance from the container.
67 *
68 * @param object|string $name
69 * @return mixed
70 */
71 protected static function resolveFacadeInstance($name)
72 {
73 if (is_object($name)) {
74 return $name;
75 }
76
77 if (isset(static::$resolvedInstance[$name])) {
78 return static::$resolvedInstance[$name];
79 }
80
81 if (static::$app) {
82 return static::$resolvedInstance[$name] = static::$app[$name];
83 }
84 }
85
86 /**
87 * Clear a resolved facade instance.
88 *
89 * @param string $name
90 * @return void
91 */
92 public static function clearResolvedInstance($name)
93 {
94 unset(static::$resolvedInstance[$name]);
95 }
96
97 /**
98 * Clear all of the resolved instances.
99 *
100 * @return void
101 */
102 public static function clearResolvedInstances()
103 {
104 static::$resolvedInstance = [];
105 }
106
107 /**
108 * Get the application instance behind the facade.
109 *
110 * @return \FluentBooking\Framework\Foundation\Application
111 */
112 public static function getFacadeApplication()
113 {
114 return static::$app;
115 }
116
117 /**
118 * Set the application instance.
119 *
120 * @param \FluentBooking\Framework\Foundation\Application $app
121 * @return void
122 */
123 public static function setFacadeApplication($app)
124 {
125 static::$app = $app;
126 }
127
128 /**
129 * Handle dynamic, static calls to the object.
130 *
131 * @param string $method
132 * @param array $args
133 * @return mixed
134 *
135 * @throws \RuntimeException
136 */
137 public static function __callStatic($method, $args)
138 {
139 $instance = static::getFacadeRoot();
140
141 if (! $instance) {
142 throw new RuntimeException('A facade root has not been set.');
143 }
144
145 return $instance->$method(...$args);
146 }
147 }
148