Event.php
969 字节
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
<?php
declare(strict_types=1);
namespace Yansongda\Pay;
use Yansongda\Pay\Contract\EventDispatcherInterface;
use Yansongda\Pay\Exception\ContainerException;
use Yansongda\Pay\Exception\InvalidConfigException;
use Yansongda\Pay\Exception\ServiceNotFoundException;
/**
* @method static Event\Event dispatch(object $event)
*/
class Event
{
/**
* @throws ContainerException
* @throws ServiceNotFoundException
* @throws InvalidConfigException
*/
public static function __callStatic(string $method, array $args): void
{
if (!Pay::hasContainer() || !Pay::has(EventDispatcherInterface::class)) {
return;
}
$class = Pay::get(EventDispatcherInterface::class);
if ($class instanceof \Psr\EventDispatcher\EventDispatcherInterface) {
$class->{$method}(...$args);
return;
}
throw new InvalidConfigException(Exception\Exception::EVENT_CONFIG_ERROR);
}
}