PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.0
6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Facade.php
kirki / libraries / framework Last commit date
Collections 1 month ago Concerns 2 weeks ago Console 4 days ago Constants 1 month ago Contracts 4 days ago Database 4 days ago Discovery 1 month ago Exceptions 4 days ago Filesystem 4 days ago Http 4 days ago Managers 4 days ago Middlewares 1 month ago Polyfill 1 month ago Routing 4 days ago Supports 4 days ago Validation 4 days ago View 4 days ago Wordpress 4 days ago ApiExceptionHandler.php 1 month ago Application.php 4 days ago Container.php 1 month ago CoreServiceProvider.php 4 days ago DTO.php 1 month ago Facade.php 1 month ago Listener.php 2 weeks ago Resource.php 4 days ago Route.php 4 days ago Sanitizer.php 4 days ago ServiceProvider.php 1 month ago SiteExceptionHandler.php 4 days ago helpers.php 4 days ago
Facade.php
95 lines
1 <?php
2
3 /**
4 * Abstract base for static facades that proxy calls to container-resolved services.
5 * Caches resolved instances per accessor and forwards __callStatic to the underlying object.
6 * Enables Facade::method() syntax throughout the framework.
7 *
8 * @package Framework
9 * @since 1.0.0
10 */
11 namespace Kirki\Framework;
12
13 \defined('ABSPATH') || exit;
14 use RuntimeException;
15 use function Kirki\Framework\app;
16 abstract class Facade
17 {
18 /**
19 * The array of resolved service instances keyed by accessor name.
20 *
21 * @var array
22 *
23 * @since 1.0.0
24 */
25 protected static $resolved_instance = [];
26 /**
27 * Whether the facade is cacheable.
28 *
29 * @var bool
30 *
31 * @since 1.0.0
32 */
33 protected static $is_cacheable = \true;
34 /**
35 * Get the accessor key for the service in the container.
36 *
37 * Child classes must implement this method to return the string accessor
38 * used to resolve the service from the application container.
39 *
40 * @return string
41 *
42 * @since 1.0.0
43 */
44 public static abstract function get_accessor();
45 /**
46 * Resolve the underlying service instance for the given accessor name.
47 *
48 * If the name is already an object, it is returned directly. Otherwise,
49 * the service is resolved from the application container and cached.
50 *
51 * @param string|object $name The accessor name or an object instance
52 *
53 * @return object The resolved service instance
54 *
55 * @since 1.0.0
56 */
57 protected static function resolved_facade_instance($name)
58 {
59 if (\is_object($name)) {
60 return $name;
61 }
62 if (static::$is_cacheable && isset(static::$resolved_instance[$name])) {
63 return static::$resolved_instance[$name];
64 }
65 $instance = app($name);
66 if (static::$is_cacheable) {
67 static::$resolved_instance[$name] = $instance;
68 }
69 return $instance;
70 }
71 /**
72 * Dynamically handle static method calls to the facade.
73 *
74 * Forwards the static call to the resolved service instance, passing all arguments.
75 * Throws a RuntimeException if the service instance cannot be resolved.
76 *
77 * @param string $method The method name being called
78 * @param array $arguments The arguments passed to the method
79 *
80 * @return mixed The result of the underlying method call
81 *
82 * @throws \RuntimeException
83 *
84 * @since 1.0.0
85 */
86 public static function __callStatic($method, $arguments)
87 {
88 $instance = static::resolved_facade_instance(static::get_accessor());
89 if (!$instance) {
90 throw new RuntimeException('A facade has not been set.');
91 }
92 return $instance->{$method}(...$arguments);
93 }
94 }
95