This commit is contained in:
yansongda 2020-10-14 23:46:30 +08:00
parent 0f55bf6618
commit b93e9942d2
2 changed files with 32 additions and 40 deletions

View File

@ -24,14 +24,10 @@ class EventServiceProvider implements ServiceProviderInterface
*/ */
public function register(Pay $pay): void public function register(Pay $pay): void
{ {
$service = function () use ($pay) { $event = $pay::make(EventDispatcher::class);
$event = $pay::make(EventDispatcher::class);
$event->addSubscriber(new KernelLogSubscriber()); $event->addSubscriber(new KernelLogSubscriber());
return $event; $pay::set(EventDispatcherInterface::class, $event);
};
$pay::set(EventDispatcherInterface::class, $service);
} }
} }

View File

@ -28,43 +28,39 @@ class LoggerServiceProvider implements ServiceProviderInterface
/* @var ConfigInterface $config */ /* @var ConfigInterface $config */
$config = Pay::get(ConfigInterface::class); $config = Pay::get(ConfigInterface::class);
$service = function () use ($config) { $logger = new class($config) extends Logger {
$logger = new class($config) extends Logger { /**
/** * @var ConfigInterface
* @var ConfigInterface */
*/ private $conf;
private $conf;
/** /**
* Bootstrap. * Bootstrap.
*/ */
public function __construct(Config $config) public function __construct(Config $config)
{ {
$this->conf = $config; $this->conf = $config;
}
/**
* __call.
*
* @author yansongda <me@yansongda.cn>
*
* @throws \Exception
*/
public function __call(string $method, array $args): void
{
if (false === $this->conf->get('log.enable', true)) {
return;
} }
/** parent::__call($method, $args);
* __call. }
*
* @author yansongda <me@yansongda.cn>
*
* @throws \Exception
*/
public function __call(string $method, array $args): void
{
if (false === $this->conf->get('log.enable', true)) {
return;
}
parent::__call($method, $args);
}
};
$logger->setConfig($config->get('log'));
return $logger;
}; };
$pay::set(LoggerInterface::class, $service); $logger->setConfig($config->get('log'));
$pay::set(LoggerInterface::class, $logger);
} }
} }