Bolt\Twig\FilesystemLoader::findTemplate PHP Method

findTemplate() protected method

Finds a file given the template name.
protected findTemplate ( string $name, boolean $throw = true ) : Bolt\Filesystem\Handler\FileInterface | false
$name string The template name.
$throw boolean Whether to throw exceptions or return false.
return Bolt\Filesystem\Handler\FileInterface | false
    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]);
    }