| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Contract\Core\Facade; |
| 4: | |
| 5: | use Salient\Contract\Core\Instantiable; |
| 6: | use Salient\Contract\Core\Unloadable; |
| 7: | use LogicException; |
| 8: | |
| 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: | * Returns the instance returned by |
| 62: | * {@see FacadeAwareInterface::withoutFacade()} if the underlying instance |
| 63: | * implements {@see FacadeAwareInterface}. |
| 64: | * |
| 65: | * @return TService |
| 66: | */ |
| 67: | public static function getInstance(): object; |
| 68: | |
| 69: | /** |
| 70: | * Forward a static method to the facade's underlying instance, loading it |
| 71: | * if necessary |
| 72: | * |
| 73: | * @param mixed[] $arguments |
| 74: | * @return mixed |
| 75: | */ |
| 76: | public static function __callStatic(string $name, array $arguments); |
| 77: | } |
| 78: |