Back to FileLayout class

Method getPath

protected string
getPath
()
Method to finds the full real file path, checking possible overrides
Returns
  • string The full path to the layout file
Since
  • 3.0
Class: FileLayout
Project: Joomla

Method getPath - Source code

/**
 * Method to finds the full real file path, checking possible overrides
 *
 * @return  string  The full path to the layout file
 *
 * @since   3.0
 */
protected function getPath()
{
    $layoutId = $this->getLayoutId();
    $includePaths = $this->getIncludePaths();
    $suffixes = $this->getSuffixes();
    $this->addDebugMessage('<strong>Layout:</strong> ' . $this->layoutId);
    if (!$layoutId) {
        $this->addDebugMessage('<strong>There is no active layout</strong>');
        return;
    }
    if (!$includePaths) {
        $this->addDebugMessage('<strong>There are no folders to search for layouts:</strong> ' . $layoutId);
        return;
    }
    $hash = md5(json_encode(array('paths' => $includePaths, 'suffixes' => $suffixes)));
    if (!empty(static::$cache[$layoutId][$hash])) {
        $this->addDebugMessage('<strong>Cached path:</strong> ' . static::$cache[$layoutId][$hash]);
        return static::$cache[$layoutId][$hash];
    }
    $this->addDebugMessage('<strong>Include Paths:</strong> ' . print_r($includePaths, true));
    // Search for suffixed versions. Example: tags.j31.php
    if ($suffixes) {
        $this->addDebugMessage('<strong>Suffixes:</strong> ' . print_r($suffixes, true));
        foreach ($suffixes as $suffix) {
            $rawPath = str_replace('.', '/', $this->layoutId) . '.' . $suffix . '.php';
            $this->addDebugMessage('<strong>Searching layout for:</strong> ' . $rawPath);
            if ($foundLayout = Path::find($this->includePaths, $rawPath)) {
                $this->addDebugMessage('<strong>Found layout:</strong> ' . $this->fullPath);
                static::$cache[$layoutId][$hash] = $foundLayout;
                return static::$cache[$layoutId][$hash];
            }
        }
    }
    // Standard version
    $rawPath = str_replace('.', '/', $this->layoutId) . '.php';
    $this->addDebugMessage('<strong>Searching layout for:</strong> ' . $rawPath);
    $foundLayout = Path::find($this->includePaths, $rawPath);
    if (!$foundLayout) {
        $this->addDebugMessage('<strong>Unable to find layout: </strong> ' . $layoutId);
        return;
    }
    $this->addDebugMessage('<strong>Found layout:</strong> ' . $foundLayout);
    static::$cache[$layoutId][$hash] = $foundLayout;
    return static::$cache[$layoutId][$hash];
}
OSZAR »