-
Notifications
You must be signed in to change notification settings - Fork 2
/
AbstractFacade.php
60 lines (50 loc) · 1.29 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
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
* This file is part of the FacadeBundle
*
* (c) Indra Gunawan <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Indragunawan\FacadeBundle;
use Psr\Container\ContainerInterface;
/**
* @author Indra Gunawan <[email protected]>
*/
abstract class AbstractFacade
{
protected static $container;
/**
* Facade service container.
*/
public static function setFacadeContainer(ContainerInterface $container)
{
static::$container = $container;
}
/**
* Get the registered id of the service.
*
* @return string
*/
abstract protected static function getFacadeAccessor();
/**
* Handle dynamic calls to the service.
*
* @param string $method
* @param array $arguments
*
* @return mixed
*
* @throws \RuntimeException
*/
public static function __callStatic($method, $arguments)
{
$class = \get_called_class();
if (!static::$container->has($class)) {
throw new \RuntimeException(sprintf('"%s" facade has not been register.', $class));
}
$service = static::$container->get($class);
return $service->$method(...$arguments);
}
}