Skip to content

Commit

Permalink
[HttpKernel] Rename the attribute class to WithLogLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
angelov committed Dec 29, 2022
1 parent 2c2453c commit 068b899
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

namespace Symfony\Component\HttpKernel\Attribute;

use Psr\Log\LogLevel;

/**
* @author Dejan Angelov <angelovdejan@protonmail.com>
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
final class LogLevel
final class WithLogLevel
{
/**
* @param \Psr\Log\LogLevel::* $level
* @param LogLevel::* $level
*/
public function __construct(public readonly string $level)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Attribute\HttpStatus;
use Symfony\Component\HttpKernel\Attribute\LogLevel;
use Symfony\Component\HttpKernel\Attribute\WithLogLevel;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
Expand Down Expand Up @@ -185,10 +185,10 @@ private function resolveLogLevel(\Throwable $throwable): string
}
}

$attributes = (new \ReflectionClass($throwable))->getAttributes(LogLevel::class);
$attributes = (new \ReflectionClass($throwable))->getAttributes(WithLogLevel::class);

if ($attributes) {
/** @var LogLevel $instance */
/** @var WithLogLevel $instance */
$instance = $attributes[0]->newInstance();

return $instance->level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
namespace Symfony\Component\HttpKernel\Tests\Attribute;

use PHPUnit\Framework\TestCase;
use Psr\Log\LogLevel as PsrLogLevel;
use Symfony\Component\HttpKernel\Attribute\LogLevel;
use Psr\Log\LogLevel;
use Symfony\Component\HttpKernel\Attribute\WithLogLevel;

/**
* @author Dejan Angelov <angelovdejan@protonmail.com>
*/
class LogLevelTest extends TestCase
class WithLogLevelTest extends TestCase
{
public function testWithValidLogLevel()
{
$logLevel = PsrLogLevel::NOTICE;
$logLevel = LogLevel::NOTICE;

$attribute = new LogLevel($logLevel);
$attribute = new WithLogLevel($logLevel);

$this->assertSame($logLevel, $attribute->level);
}
Expand All @@ -34,6 +34,6 @@ public function testWithInvalidLogLevel()
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid log level "invalid".');

new LogLevel('invalid');
new WithLogLevel('invalid');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\HttpStatus;
use Symfony\Component\HttpKernel\Attribute\LogLevel;
use Symfony\Component\HttpKernel\Attribute\WithLogLevel;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
Expand Down Expand Up @@ -348,7 +349,7 @@ class WithGeneralAttribute extends \Exception
{
}

#[LogLevel(\Psr\Log\LogLevel::WARNING)]
#[WithLogLevel(LogLevel::WARNING)]
class WarningWithLogLevelAttribute extends \Exception
{
}

0 comments on commit 068b899

Please sign in to comment.