Skip to content
Snippets Groups Projects
Commit 4bf33c29 authored by dyszczo's avatar dyszczo
Browse files

dir resolver implementation

parent 2501b350
No related branches found
No related tags found
2 merge requests!8feat/woo template,!3Feature/implementation
<?php
namespace WPDesk\View\Resolver;
use WPDesk\View\Renderer\Renderer;
use WPDesk\View\Resolver\Exception\CanNotResolve;
/**
* Class should resolve name by serching in provided dir. If empty then current dir
*
* @package WPDesk\View\Resolver
*/
class DirResolver implements Resolver
{
/** @var string */
private $dir;
/**
* Base path for templates ie. subdir
*
* @param $template_base_path
*/
public function __construct($dir)
{
$this->dir = $dir;
}
/**
* Resolve name to full path
*
* @param string $name
* @param Renderer|null $renderer
*
* @return string
*/
public function resolve($name, Renderer $renderer = null)
{
$dir = rtrim($this->dir, '/');
$fullName = $dir . '/' . $name . '.php';
if (file_exists($fullName)) {
return $fullName;
}
throw new CanNotResolve("Cannot resolve {$name}");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment