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
{
$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, $service);
$pay::set(EventDispatcherInterface::class, $event);
}
}

View File

@ -28,43 +28,39 @@ class LoggerServiceProvider implements ServiceProviderInterface
/* @var ConfigInterface $config */
$config = Pay::get(ConfigInterface::class);
$service = function () use ($config) {
$logger = new class($config) extends Logger {
/**
* @var ConfigInterface
*/
private $conf;
$logger = new class($config) extends Logger {
/**
* @var ConfigInterface
*/
private $conf;
/**
* Bootstrap.
*/
public function __construct(Config $config)
{
$this->conf = $config;
/**
* Bootstrap.
*/
public function __construct(Config $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;
}
/**
* __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;
parent::__call($method, $args);
}
};
$pay::set(LoggerInterface::class, $service);
$logger->setConfig($config->get('log'));
$pay::set(LoggerInterface::class, $logger);
}
}