File "ChainResolver.php"
Full Path: /home/siazco/grocery.siazco.se/wp-content/plugins/flexible-shipping/vendor_prefixed/wpdesk/wp-view/src/Resolver/ChainResolver.php
File size: 1.31 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace FSVendor\WPDesk\View\Resolver;
use FSVendor\WPDesk\View\Renderer\Renderer;
use FSVendor\WPDesk\View\Resolver\Exception\CanNotResolve;
/**
* Provide resolvers and this class can try them one after another
*
* @package WPDesk\View\Resolver
*/
class ChainResolver implements Resolver
{
/** @var Resolver[] */
private $resolvers;
/**
* Warning: function with variadic input. Input should be list of Resolver instances.
*/
public function __construct()
{
$args = func_get_args();
foreach ($args as $resolver) {
$this->appendResolver($resolver);
}
}
/**
* Append resolver to the end of the list
*
* @param Resolver $resolver
*/
public function appendResolver($resolver)
{
$this->resolvers[] = $resolver;
}
/**
* Resolve name to full path
*
* @param string $name
* @param Renderer|null $renderer
*
* @return string
*/
public function resolve($name, Renderer $renderer = null)
{
foreach ($this->resolvers as $resolver) {
try {
return $resolver->resolve($name);
} catch (CanNotResolve $e) {
// not interested
}
}
throw new CanNotResolve("Cannot resolve {$name}");
}
}