Skip to content

Commit

Permalink
Add deprecation message for ExtensionInterface::getLastModified() met…
Browse files Browse the repository at this point in the history
…hod not implemented
  • Loading branch information
GromNaN committed Dec 24, 2024
1 parent 95c05cd commit 3a94244
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/ExtensionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ public function getLastModified(): int
$lastModified = 0;
foreach ($this->extensions as $extension) {
$r = new \ReflectionObject($extension);
$lastModified = max(match(true) {
$r->hasMethod('getLastModified') => $extension->getLastModified(),
is_file($r->getFileName()) => filemtime($r->getFileName()),
default => 0,
}, $lastModified);

if ($r->hasMethod('getLastModified')) {
$lastModified = max($extension->getLastModified(), $lastModified);
} else {
trigger_deprecation('twig/twig', '3.18', 'Not implementing "%s::getLastModified()" in "%s" is deprecated.', ExtensionInterface::class, $extension::class);

if (is_file($r->getFileName())) {
$lastModified = max(filemtime($r->getFileName()), $lastModified);
}
}
}

return $this->lastModified = $lastModified;
Expand Down
5 changes: 5 additions & 0 deletions tests/CustomExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public function getOperators(): array
{
return $this->operators;
}

public function getLastModified(): int
{
return 0;
}
}
2 changes: 1 addition & 1 deletion tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function testAddExtension()

public function testAddMockExtension()
{
$extension = $this->createMock(ExtensionInterface::class);
$extension = $this->createMock(AbstractExtension::class);
$loader = new ArrayLoader(['page' => 'hey']);

$twig = new Environment($loader);
Expand Down

0 comments on commit 3a94244

Please sign in to comment.