File tree Expand file tree Collapse file tree 7 files changed +29
-12
lines changed
Expand file tree Collapse file tree 7 files changed +29
-12
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ final class PostsLastModifiedDeterminator implements LastModifiedDeterminator
9999 private readonly BlogPostRepository $blogPostRepository,
100100 ) {
101101
102- public function getLastModified(Request $request): ?\DateTime
102+ public function getLastModified(Request $request): ?\DateTimeInterface
103103 {
104104 $post = $this->blogPostRepository->findLatest();
105105
Original file line number Diff line number Diff line change 77use Symfony \Component \DependencyInjection \Extension \Extension ;
88use Symfony \Component \DependencyInjection \Loader \PhpFileLoader ;
99
10+ /**
11+ * @internal
12+ * @psalm-internal Webfactory\HttpCacheBundle
13+ */
1014class WebfactoryHttpCacheExtension extends Extension
1115{
1216 public function load (array $ configs , ContainerBuilder $ container ): void
Original file line number Diff line number Diff line change 1010namespace Webfactory \HttpCacheBundle \NotModified \Attribute ;
1111
1212use Attribute ;
13- use DateTime ;
13+ use DateTimeInterface ;
1414use RuntimeException ;
1515use Symfony \Component \DependencyInjection \ContainerInterface ;
1616use Symfony \Component \HttpFoundation \Request ;
@@ -27,14 +27,18 @@ final class ReplaceWithNotModifiedResponse
2727 /** @var LastModifiedDeterminator[] */
2828 private array $ lastModifiedDeterminators ;
2929 private ContainerInterface $ container ;
30- private ?DateTime $ lastModified = null ;
30+ private ?DateTimeInterface $ lastModified = null ;
3131
3232 public function __construct (
3333 private readonly array $ parameters ,
3434 ) {
3535 }
3636
37- public function determineLastModified (Request $ request ): ?DateTime
37+ /**
38+ * @internal
39+ * @psalm-internal Webfactory\HttpCacheBundle
40+ */
41+ public function determineLastModified (Request $ request ): ?DateTimeInterface
3842 {
3943 $ this ->initialiseLastModifiedDeterminators ();
4044
@@ -48,6 +52,10 @@ public function determineLastModified(Request $request): ?DateTime
4852 return $ this ->lastModified ;
4953 }
5054
55+ /**
56+ * @internal
57+ * @psalm-internal Webfactory\HttpCacheBundle
58+ */
5159 public function setContainer (ContainerInterface $ container ): void
5260 {
5361 $ this ->container = $ container ;
Original file line number Diff line number Diff line change 2020 * Symfony EventListener for adding a "last modified" header to the response on the one hand. On the other hand, it
2121 * replaces the execution of a controller action with a Not Modified HTTP response, if no newer "last modified" date is
2222 * determined than the one in the header of a subsequent request.
23+ *
24+ * @internal
25+ * @psalm-internal Webfactory\HttpCacheBundle
2326 */
2427final class EventListener
2528{
Original file line number Diff line number Diff line change 99
1010namespace Webfactory \HttpCacheBundle \NotModified ;
1111
12- use DateTime ;
12+ use DateTimeInterface ;
1313use Symfony \Component \HttpFoundation \Request ;
1414
1515/**
2222interface LastModifiedDeterminator
2323{
2424 /**
25- * @return DateTime|null
25+ * @return ?DateTimeInterface
2626 */
2727 public function getLastModified (Request $ request );
2828}
Original file line number Diff line number Diff line change 1010namespace Webfactory \HttpCacheBundle \Tests \NotModified \Attribute ;
1111
1212use DateTime ;
13+ use DateTimeInterface ;
1314use PHPUnit \Framework \Attributes \DoesNotPerformAssertions ;
1415use PHPUnit \Framework \Attributes \Group ;
1516use PHPUnit \Framework \Attributes \Test ;
@@ -103,14 +104,14 @@ final class FakeLastModifiedDeterminatorWithoutInterface
103104
104105final class MyLastModifedDeterminator implements LastModifiedDeterminator
105106{
106- private DateTime $ lastModified ;
107+ private ? DateTimeInterface $ lastModified ;
107108
108- public function __construct (?DateTime $ lastModified = null )
109+ public function __construct (?DateTimeInterface $ lastModified = null )
109110 {
110111 $ this ->lastModified = $ lastModified ?: DateTime::createFromFormat ('U ' , time ());
111112 }
112113
113- public function getLastModified (Request $ request ): DateTime
114+ public function getLastModified (Request $ request ): ? DateTimeInterface
114115 {
115116 return $ this ->lastModified ;
116117 }
Original file line number Diff line number Diff line change 1111
1212use Closure ;
1313use DateTime ;
14+ use DateTimeInterface ;
1415use Error ;
1516use PHPUnit \Framework \Attributes \Group ;
1617use PHPUnit \Framework \Attributes \Test ;
@@ -269,23 +270,23 @@ public static function actionWithMoreThanOneAttribute(): Response
269270
270271final class AbstainingLastModifiedDeterminator implements LastModifiedDeterminator
271272{
272- public function getLastModified (Request $ request ): ?DateTime
273+ public function getLastModified (Request $ request ): ?DateTimeInterface
273274 {
274275 return null ;
275276 }
276277}
277278
278279final class OneDayAgoModifiedLastModifiedDeterminator implements LastModifiedDeterminator
279280{
280- public function getLastModified (Request $ request ): DateTime
281+ public function getLastModified (Request $ request ): ? DateTimeInterface
281282 {
282283 return DateTime::createFromFormat ('U ' , time () - 86400 );
283284 }
284285}
285286
286287final class FixedDateAgoModifiedLastModifiedDeterminator implements LastModifiedDeterminator
287288{
288- public function getLastModified (Request $ request ): DateTime
289+ public function getLastModified (Request $ request ): ? DateTimeInterface
289290 {
290291 return new DateTime ('2000-01-01 ' );
291292 }
You can’t perform that action at this time.
0 commit comments