8000 [HttpKernel] Handle previously converted `DateTime` arguments by mbabker · Pull Request #46199 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Handle previously converted DateTime arguments #46199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Handle previously converted DateTime arguments
  • Loading branch information
mbabker committed May 1, 2022
commit a48ecb69ba9c7037142e12ebc27e0fcef258e0a6
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
$value = $request->attributes->get($argument->getName());

if ($value instanceof \DateTimeInterface) {
yield $value;

return;
}

if ($argument->isNullable() && !$value) {
yield null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ public function testNullableWithEmptyAttribute()
$this->assertNull($results[0]);
}

public function testPreviouslyConvertedAttribute()
{
$resolver = new DateTimeValueResolver();

$argument = new ArgumentMetadata('dummy', \DateTime::class, false, false, null, true);
$request = self::requestWithAttributes(['dummy' => $datetime = new \DateTime()]);

/** @var \Generator $results */
$results = $resolver->resolve($request, $argument);
$results = iterator_to_array($results);

$this->assertCount(1, $results);
$this->assertSame($datetime, $results[0]);
}

public function testCustomClass()
{
date_default_timezone_set('UTC');
Expand Down
0