for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace League\Plates\Template\ResolveTemplatePath;
use League\Plates\Exception\TemplateNotFound;
use League\Plates\Template\Name;
use League\Plates\Template\ResolveTemplatePath;
use League\Plates\Template\Theme;
final class ThemeResolveTemplatePath implements ResolveTemplatePath
{
private $theme;
public function __construct(Theme $theme) {
$this->theme = $theme;
}
public function __invoke(Name $name): string {
$searchedPaths = [];
foreach ($this->theme->listThemeHierarchy() as $theme) {
$path = $theme->dir() . '/' . $name->getName() . '.' . $name->getEngine()->getFileExtension();
if (is_file($path)) {
return $path;
$searchedPaths[] = [$theme->name(), $path];
throw new TemplateNotFound(
$name->getName(),
array_map(function(array $tup) {
return $tup[1];
}, $searchedPaths),
sprintf('The template "%s" was not found in the following themes: %s',
implode(', ', array_map(function(array $tup) {
return implode(':', $tup);
}, $searchedPaths))
)
);
public function exists(Name $name): bool
try {
$this($name);
return true;
} catch (TemplateNotFound $exception) {
return false;