@trigger_error('The '.TemplateLocator::class.' class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.', \E_USER_DEPRECATED);
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
/**
* TemplateLocator locates templates in bundles.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since version 4.3, to be removed in 5.0; use Twig instead.
*/
class TemplateLocator implements FileLocatorInterface
{
protected $locator;
protected $cache;
private $cacheHits = [];
/**
* @param string $cacheDir The cache path
*/
public function __construct(FileLocatorInterface $locator, string $cacheDir = null)
{
if (null !== $cacheDir && file_exists($cache = $cacheDir.'/templates.php')) {
$this->cache = require $cache;
}
$this->locator = $locator;
}
/**
* Returns a full path for a given file.
*
* @return string The full path for the file
*/
protected function getCacheKey($template)
{
return $template->getLogicalName();
}
/**
* Returns a full path for a given file.
*
* @param TemplateReferenceInterface $template A template
* @param string $currentPath Unused
* @param bool $first Unused
*
* @return string The full path for the file
*
* @throws \InvalidArgumentException When the template is not an instance of TemplateReferenceInterface
* @throws \InvalidArgumentException When the template file can not be found
*/
public function locate($template, $currentPath = null, $first = true)
{
if (!$template instanceof TemplateReferenceInterface) {
throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.');