/
AbstractFacade.php
49 lines (40 loc) · 1.35 KB
/
AbstractFacade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace LaminasFacade\Facades;
use Laminas\Mvc\Application;
use Laminas\Stdlib\ArrayUtils;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Container\ContainerExceptionInterface;
abstract class AbstractFacade
{
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public static function __callStatic(string $method, ?array $args = null)
{
$instance = static::resolveFacadeInstance();
return $instance->$method(...$args);
}
/**
* @throws \Exception if not implemented
*/
protected static function getFacadeAccessor(): string
{
throw new \Exception('AbstractFacade does not implement getFacadeAccessor method.');
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws \Exception
*/
private static function resolveFacadeInstance(): object
{
$appConfigDir = __DIR__ . '/../../../../../config';
$appConfig = require $appConfigDir . '/application.config.php';
if (file_exists(__DIR__ . '/development.config.php')) {
$appConfig = ArrayUtils::merge($appConfig, require $appConfigDir . '/development.config.php');
}
return Application::init($appConfig)->getServiceManager()->get(static::getFacadeAccessor());
}
}