PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Facades / Facade.php
wp-staging / Framework / Facades Last commit date
UI 1 day ago DataEncryption.php 5 months ago Escape.php 3 years ago Facade.php 1 day ago Hooks.php 4 months ago Info.php 1 year ago PhpAdapter.php 2 years ago Sanitize.php 4 months ago SettingsTable.php 1 day ago
Facade.php
108 lines
1 <?php
2
3 namespace WPStaging\Framework\Facades;
4
5 use Exception;
6 use ReflectionMethod;
7 use RuntimeException;
8 use WPStaging\Core\WPStaging;
9
10
11
12
13
14
15
16
17
18 abstract class Facade
19 {
20 protected static $facadeInstances = [];
21
22
23
24
25
26
27
28
29 public static function swapInstance($instance)
30 {
31 $oldInstance = static::$facadeInstances[static::getFacadeAccessor()];
32 static::setInstance($instance);
33 return $oldInstance;
34 }
35
36
37
38
39
40
41 public static function setInstance($instance)
42 {
43 $class = static::getFacadeAccessor();
44 if ($instance instanceof $class) {
45 static::$facadeInstances[static::getFacadeAccessor()] = $instance;
46 return;
47 }
48
49 throw new RuntimeException('Given instance is not an instance of ' . $class);
50 }
51
52
53
54
55
56
57 public static function __callStatic($method, $args)
58 {
59 $instance = static::getInstance();
60
61 if ($instance === null) {
62 throw new RuntimeException('A facade instance cannot be created!');
63 }
64
65 if (!method_exists($instance, $method)) {
66 throw new RuntimeException('Method does not exists!');
67 }
68
69 $reflection = new ReflectionMethod($instance, $method);
70 if (!$reflection->isPublic()) {
71 throw new RuntimeException('Can only call a public method!');
72 }
73
74 return $instance->$method(...$args);
75 }
76
77 protected static function createInstance()
78 {
79 try {
80 static::$facadeInstances[static::getFacadeAccessor()] = WPStaging::make(static::getFacadeAccessor());
81 } catch (Exception $ex) {
82 static::$facadeInstances[static::getFacadeAccessor()] = null;
83 }
84 }
85
86
87 protected static function getInstance()
88 {
89 if (!isset(static::$facadeInstances[static::getFacadeAccessor()]) || static::$facadeInstances[static::getFacadeAccessor()] === null) {
90 static::createInstance();
91 }
92
93 return static::$facadeInstances[static::getFacadeAccessor()];
94 }
95
96
97
98
99
100
101
102
103 protected static function getFacadeAccessor()
104 {
105 throw new RuntimeException('Facade does not implement getFacadeAccessor method.');
106 }
107 }
108