1: <?php declare(strict_types=1);
2:
3: namespace Salient\Contract\Core;
4:
5: use LogicException;
6:
7: /**
8: * Provides a static interface to an underlying instance
9: *
10: * @api
11: *
12: * @template TService of Instantiable
13: */
14: interface FacadeInterface
15: {
16: /**
17: * Check if the facade's underlying instance is loaded
18: */
19: public static function isLoaded(): bool;
20:
21: /**
22: * Load the facade's underlying instance
23: *
24: * If `$instance` is `null`, the facade creates a new underlying instance.
25: *
26: * Then, if the instance implements {@see FacadeAwareInterface}, it is
27: * replaced with the return value of
28: * {@see FacadeAwareInterface::withFacade()}.
29: *
30: * @param TService|null $instance
31: * @throws LogicException if the facade's underlying instance is already
32: * loaded.
33: */
34: public static function load(?object $instance = null): void;
35:
36: /**
37: * Replace the facade's underlying instance
38: *
39: * Equivalent to calling {@see unload()} before passing `$instance` to
40: * {@see load()}.
41: *
42: * @param TService $instance
43: */
44: public static function swap(object $instance): void;
45:
46: /**
47: * Remove the facade's underlying instance if loaded
48: *
49: * If the underlying instance implements {@see FacadeAwareInterface}, it is
50: * replaced with the return value of
51: * {@see FacadeAwareInterface::withoutFacade()}.
52: *
53: * Then, if the instance implements {@see Unloadable}, its
54: * {@see Unloadable::unload()} method is called.
55: */
56: public static function unload(): void;
57:
58: /**
59: * Get the facade's underlying instance, loading it if necessary
60: *
61: * @return TService
62: */
63: public static function getInstance(): object;
64:
65: /**
66: * Forward a static method to the facade's underlying instance, loading it
67: * if necessary
68: *
69: * @param mixed[] $arguments
70: * @return mixed
71: */
72: public static function __callStatic(string $name, array $arguments);
73: }
74: