Skip to content

Commit f078f5c

Browse files
feature #48098 [HttpKernel]  Resolve DateTime value using the Clock (GromNaN)
This PR was merged into the 6.3 branch. Discussion ---------- [HttpKernel]  Resolve DateTime value using the Clock | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | TODO In order to mock the current time in functional test cases by injecting a `Symfony\Component\Clock\MockClock` as `clock` service. This is necessary when a `DateTimeInterface` argument is not nullable and we expect the current date time by default. Example when 2 routes are configured on the same controller with an optional parameter. ```php class TvGridController { #[Route('/', name: 'prime_now')] #[Route('/{date}', name: 'prime_date'] public function prime(\DateTimeInterface $date) { return new Response('Grid for date: '.$date->format('Y-m-d')); } } ``` Commits ------- 4917528d9a Resolve DateTime value using the clock
2 parents a77042a + 5acb3c7 commit f078f5c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Resources/config/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
->tag('controller.argument_value_resolver', ['priority' => 100])
5656

5757
->set('argument_resolver.datetime', DateTimeValueResolver::class)
58+
->args([
59+
service('clock')->nullOnInvalid(),
60+
])
5861
->tag('controller.argument_value_resolver', ['priority' => 100])
5962

6063
->set('argument_resolver.request_attribute', RequestAttributeValueResolver::class)

0 commit comments

Comments
 (0)