Pico::load404Content PHP Method

load404Content() public method

Returns the raw contents of the first found 404 file when traversing up from the directory the requested file is in
See also: Pico::getRawContent()
public load404Content ( string $file ) : string
$file string path to requested (but not existing) file
return string raw contents of the 404 file
    public function load404Content($file)
    {
        $contentDir = $this->getConfig('content_dir');
        $contentDirLength = strlen($contentDir);
        if (substr($file, 0, $contentDirLength) === $contentDir) {
            $errorFileDir = substr($file, $contentDirLength);
            while ($errorFileDir !== '.') {
                $errorFileDir = dirname($errorFileDir);
                $errorFile = $errorFileDir . '/404' . $this->getConfig('content_ext');
                if (file_exists($this->getConfig('content_dir') . $errorFile)) {
                    return $this->loadFileContent($this->getConfig('content_dir') . $errorFile);
                }
            }
        } elseif (file_exists($this->getConfig('content_dir') . '404' . $this->getConfig('content_ext'))) {
            // provided that the requested file is not in the regular
            // content directory, fallback to Pico's global `404.md`
            return $this->loadFileContent($this->getConfig('content_dir') . '404' . $this->getConfig('content_ext'));
        }
        $errorFile = $this->getConfig('content_dir') . '404' . $this->getConfig('content_ext');
        throw new RuntimeException('Required "' . $errorFile . '" not found');
    }