Event.php 969 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Pay;
  4. use Yansongda\Pay\Contract\EventDispatcherInterface;
  5. use Yansongda\Pay\Exception\ContainerException;
  6. use Yansongda\Pay\Exception\InvalidConfigException;
  7. use Yansongda\Pay\Exception\ServiceNotFoundException;
  8. /**
  9. * @method static Event\Event dispatch(object $event)
  10. */
  11. class Event
  12. {
  13. /**
  14. * @throws ContainerException
  15. * @throws ServiceNotFoundException
  16. * @throws InvalidConfigException
  17. */
  18. public static function __callStatic(string $method, array $args): void
  19. {
  20. if (!Pay::hasContainer() || !Pay::has(EventDispatcherInterface::class)) {
  21. return;
  22. }
  23. $class = Pay::get(EventDispatcherInterface::class);
  24. if ($class instanceof \Psr\EventDispatcher\EventDispatcherInterface) {
  25. $class->{$method}(...$args);
  26. return;
  27. }
  28. throw new InvalidConfigException(Exception\Exception::EVENT_CONFIG_ERROR);
  29. }
  30. }