Skip to content

Commit

Permalink
Loader::isExpired() deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 21, 2024
1 parent 1b1ec34 commit 5735804
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/Latte/Loader.php
Expand Up @@ -22,6 +22,7 @@ function getContent(string $name): string;

/**
* Checks whether template is expired.
* @deprecated
*/
function isExpired(string $name, int $time): bool;

Expand Down
3 changes: 1 addition & 2 deletions src/Latte/Loaders/FileLoader.php
Expand Up @@ -50,8 +50,7 @@ public function getContent(string $fileName): string

public function isExpired(string $file, int $time): bool
{
$mtime = @filemtime($this->baseDir . $file); // @ - stat may fail
return !$mtime || $mtime > $time;
return false;
}


Expand Down
9 changes: 0 additions & 9 deletions tests/common/Loaders.FileLoader.phpt
Expand Up @@ -15,12 +15,6 @@ require __DIR__ . '/../bootstrap.php';
$loader = new FileLoader;
Assert::same(file_get_contents(__FILE__), $loader->getContent(__FILE__));

Assert::false($loader->isExpired(__FILE__, filemtime(__FILE__)));
Assert::false($loader->isExpired(__FILE__, filemtime(__FILE__) + 1));
Assert::true($loader->isExpired(__FILE__, filemtime(__FILE__) - 1));

Assert::true($loader->isExpired('nonexist', filemtime(__FILE__)));

Assert::same('/a/b/inner', strtr($loader->getReferredName('inner', '/a\\b/c'), '\\', '/'));
Assert::same('/a/b/c', strtr($loader->getReferredName('/a/b/c', '/a/b/c'), '\\', '/'));
Assert::same('/a/c', strtr($loader->getReferredName('../c', '/a/b/c'), '\\', '/'));
Expand All @@ -42,9 +36,6 @@ Assert::exception(
"Template '%a%common/.././../file' is not within the allowed path '%a%'.",
);

Assert::false($loader->isExpired('common/' . basename(__FILE__), filemtime(__FILE__) + 1));
Assert::true($loader->isExpired('common/' . basename(__FILE__), filemtime(__FILE__) - 1));

Assert::same('common' . DIRECTORY_SEPARATOR . 'new', $loader->getReferredName('new', 'common/file'));
Assert::same('common', $loader->getReferredName('common', 'file'));
Assert::same('..' . DIRECTORY_SEPARATOR . 'tests', $loader->getReferredName('../tests', 'file'));
Expand Down
6 changes: 0 additions & 6 deletions tests/common/Loaders.StringLoader.phpt
Expand Up @@ -16,9 +16,6 @@ test('', function () {
$loader = new StringLoader;
Assert::same('content', $loader->getContent('content'));

Assert::false($loader->isExpired('content', 0));
Assert::false($loader->isExpired('content', 1));

Assert::exception(
fn() => $loader->getReferredName('inner', 'referrer'),
LogicException::class,
Expand All @@ -31,8 +28,5 @@ test('', function () {
Assert::same('maincontent', $loader->getContent('main'));
Assert::same('othercontent', $loader->getContent('other'));

Assert::false($loader->isExpired('main', 0));
Assert::false($loader->isExpired('undefined', 1));

Assert::same('other', $loader->getReferredName('other', 'referrer'));
});

0 comments on commit 5735804

Please sign in to comment.