1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<?php
namespace ICanBoogie\Module;
use ICanBoogie\Module;
use ICanBoogie\Render\TemplateResolver;
use ICanBoogie\Render\TemplateResolverDecorator;
use ICanBoogie\Render\TemplateResolverDecoratorTrait;
use ICanBoogie\Render\TemplateResolverTrait;
class ModuleTemplateResolver implements TemplateResolverDecorator
{
use TemplateResolverTrait;
use TemplateResolverDecoratorTrait;
private $modules;
public function __construct(TemplateResolver $template_resolver, ModuleCollection $modules)
{
$this->template_resolver = $template_resolver;
$this->modules = $modules;
}
public function resolve($name, array $extensions, &$tried = [])
{
$template_pathname = $this->template_resolver->resolve($name, $extensions, $tried);
if ($template_pathname)
{
return $template_pathname;
}
$modules = $this->modules;
$module_id = dirname($name);
if (empty($modules[$module_id]))
{
return null;
}
return $this->resolve_from_module($modules[$module_id], $name, $extensions, $tried);
}
public function resolve_from_module(Module $module, $name, array $extensions, &$tried = [])
{
$paths = [];
while ($module)
{
$paths[] = $module->path . 'templates' . DIRECTORY_SEPARATOR;
$module = $module->parent;
}
$name = basename($name);
return $this->resolve_path($this
->resolve_tries($paths, $name, $extensions), $tried);
}
}