Added the default implement for Psr\Log\LoggerInterface. (#6488)

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
Deeka Wong 2024-01-22 15:40:06 +08:00 committed by GitHub
parent 5726bc22b8
commit b63bfd9eef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 14 additions and 43 deletions

View File

@ -3,6 +3,7 @@
## Added
- [#6483](https://github.com/hyperf/hyperf/pull/6483) [#6487] (https://github.com/hyperf/hyperf/pull/6487) Added new ways to register crontab.
- [#6488](https://github.com/hyperf/hyperf/pull/6488) Added the default implement for `Psr\Log\LoggerInterface`.
## Optimized

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
*/
namespace Hyperf\Coordinator;
use Hyperf\Contract\StdoutLoggerInterface;
use Psr\Log\LoggerInterface;
use Throwable;
use function Hyperf\Coroutine\go;
@ -28,7 +28,7 @@ class Timer
private static int $round = 0;
public function __construct(private ?StdoutLoggerInterface $logger = null)
public function __construct(private ?LoggerInterface $logger = null)
{
}

View File

@ -21,10 +21,12 @@ use Hyperf\Crontab\Event\AfterExecute;
use Hyperf\Crontab\Event\BeforeExecute;
use Hyperf\Crontab\Event\FailToExecute;
use Hyperf\Crontab\Exception\InvalidArgumentException;
use Hyperf\Crontab\LoggerInterface;
use Hyperf\Crontab\Mutex\ServerMutex;
use Hyperf\Crontab\Mutex\TaskMutex;
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface as PsrLoggerInterface;
use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
@ -34,7 +36,7 @@ use function Hyperf\Support\make;
class Executor
{
protected ?StdoutLoggerInterface $logger = null;
protected ?PsrLoggerInterface $logger = null;
protected ?TaskMutex $taskMutex = null;
@ -46,7 +48,9 @@ class Executor
public function __construct(protected ContainerInterface $container)
{
if ($container->has(StdoutLoggerInterface::class)) {
if ($container->has(LoggerInterface::class)) {
$this->logger = $container->get(LoggerInterface::class);
} elseif ($container->has(StdoutLoggerInterface::class)) {
$this->logger = $container->get(StdoutLoggerInterface::class);
}
if ($container->has(EventDispatcherInterface::class)) {

View File

@ -11,11 +11,16 @@ declare(strict_types=1);
*/
namespace Hyperf\Logger;
use Psr\Log\LoggerInterface;
class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => [
LoggerInterface::class => fn ($container) => $container->get(LoggerFactory::class)->make(),
],
'publish' => [
[
'id' => 'config',

View File

@ -1,39 +0,0 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Logger;
use Hyperf\Logger\ConfigProvider;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\Hyperf\Logger\ConfigProvider::class)]
class ConfigProviderTest extends TestCase
{
public function testInvoke()
{
$dir = str_replace('/tests', '/src', __DIR__);
$this->assertSame([
'publish' => [
[
'id' => 'config',
'description' => 'The config for logger.',
'source' => $dir . '/../publish/logger.php',
'destination' => BASE_PATH . '/config/autoload/logger.php',
],
],
], (new ConfigProvider())());
}
}