protected function findTemplate($name, $throw = true)
{
$name = $this->normalizeName($name);
if (isset($this->cache[$name])) {
return $this->cache[$name];
}
if (isset($this->errorCache[$name])) {
if (!$throw) {
return false;
}
throw new LoaderError($this->errorCache[$name]);
}
$this->validateName($name);
list($namespace, $shortName) = $this->parseName($name);
if (!isset($this->paths[$namespace])) {
$this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace);
if (!$throw) {
return false;
}
throw new LoaderError($this->errorCache[$name]);
}
foreach ($this->paths[$namespace] as $dir) {
/** @var DirectoryInterface $dir */
try {
$file = $dir->getFile($shortName);
} catch (ExceptionInterface $e) {
continue;
}
if ($file->exists()) {
return $this->cache[$name] = $file;
}
}
$paths = array_map(function (DirectoryInterface $dir) {
return $dir->getFullPath();
}, $this->paths[$namespace]);
$paths = implode(', ', $paths);
$this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, $paths);
if (!$throw) {
return false;
}
throw new LoaderError($this->errorCache[$name]);
}