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

implementation of wp theme resolver

parent 0a46fcd1
No related branches found
No related tags found
2 merge requests!8feat/woo template,!3Feature/implementation
<?php
namespace WPDesk\View\Resolver\Exception;
class CanNotResolve extends \RuntimeException
{
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ interface Resolver {
* @param string $name
* @param null|Resolver $renderer
*
* @return mixed
* @return string
*/
public function resolve($name, Renderer $renderer = null);
}
<?php
namespace WPDesk\View\Resolver;
use WPDesk\View\Renderer\Renderer;
use WPDesk\View\Resolver\Exception\CanNotResolve;
/**
* Class should resolve name by standard wp theme resolve
*
* @package WPDesk\View\Resolver
*/
class WPThemeResolver implements Resolver
{
/** @var string */
private $template_base_path;
/**
* Base path for templates ie. subdir
*
* @param $template_base_path
*/
public function __construct($template_base_path)
{
$this->template_base_path = $template_base_path;
}
/**
* Resolve name to full path
*
* @param string $name
* @param Renderer|null $renderer
*
* @return string
*/
public function resolve($name, Renderer $renderer = null)
{
$templateFile = locate_template(
[
trailingslashit($this->template_base_path) . $name . '.php',
]
);
if ( ! $templateFile) {
throw new CanNotResolve("Cannot resolve {$name}");
}
return $templateFile;
}
}
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