Skip to content

Commit

Permalink
feature #48876 [HttpKernel] Rename HttpStatus atribute to WithHttpSta…
Browse files Browse the repository at this point in the history
…tus (fabpot)

This PR was merged into the 6.3 branch.

Discussion
----------

[HttpKernel] Rename HttpStatus atribute to WithHttpStatus

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes-ish
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Refs #48352 and #48747

As discussed in the 2 referenced PRs for better naming consistency.

Commits
-------

fece766 [HttpKernel] Rename HttpStatus atribute to WithHttpStatus
  • Loading branch information
fabpot committed Jan 6, 2023
2 parents ed96673 + fece766 commit f4a9a5d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Dejan Angelov <angelovdejan@protonmail.com>
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class HttpStatus
class WithHttpStatus
{
/**
* @param array<string, string> $headers
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CHANGELOG

* Deprecate parameters `container.dumper.inline_factories` and `container.dumper.inline_class_loader`, use `.container.dumper.inline_factories` and `.container.dumper.inline_class_loader` instead
* `FileProfilerStorage` removes profiles automatically after two days
* Add `#[HttpStatus]` for defining status codes for exceptions
* Add `#[WithHttpStatus]` for defining status codes for exceptions
* Use an instance of `Psr\Clock\ClockInterface` to generate the current date time in `DateTimeValueResolver`
* Add `#[WithLogLevel]` for defining log levels for exceptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Attribute\HttpStatus;
use Symfony\Component\HttpKernel\Attribute\WithHttpStatus;
use Symfony\Component\HttpKernel\Attribute\WithLogLevel;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
Expand Down Expand Up @@ -71,10 +71,10 @@ public function logKernelException(ExceptionEvent $event)
// There's no specific status code defined in the configuration for this exception
if (!$throwable instanceof HttpExceptionInterface) {
$class = new \ReflectionClass($throwable);
$attributes = $class->getAttributes(HttpStatus::class, \ReflectionAttribute::IS_INSTANCEOF);
$attributes = $class->getAttributes(WithHttpStatus::class, \ReflectionAttribute::IS_INSTANCEOF);

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

$throwable = new HttpException($instance->statusCode, $throwable->getMessage(), $throwable, $instance->headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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\WithHttpStatus;
use Symfony\Component\HttpKernel\Attribute\WithLogLevel;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
Expand Down Expand Up @@ -321,7 +321,7 @@ public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = tr
}

#[\Attribute(\Attribute::TARGET_CLASS)]
class UserProvidedHttpStatusCodeAttribute extends HttpStatus
class UserProvidedHttpStatusCodeAttribute extends WithHttpStatus
{
public function __construct(array $headers = [])
{
Expand All @@ -339,7 +339,7 @@ class WithCustomUserProvidedAttribute extends \Exception
{
}

#[HttpStatus(
#[WithHttpStatus(
statusCode: Response::HTTP_PRECONDITION_FAILED,
headers: [
'some' => 'thing',
Expand Down

0 comments on commit f4a9a5d

Please sign in to comment.