CMS\Page::fromPath PHP Method

fromPath() public static method

Create new File instance from path
public static fromPath ( string $path, array $meta = [] ) : static
$path string
$meta array
return static
    public static function fromPath($path, array $meta = [])
    {
        if (is_file($file = $path . '.html') || is_file($file = $path . '.md') || is_file($file = $path . '.latte') || is_file($file = $path . '.phtml') || is_dir($path) && (is_file($file = $path . '/index.html') || is_file($file = $path . '/index.md') || is_file($file = $path . '/index.latte') || is_file($file = $path . '/index.phtml'))) {
            return new static(realpath($file), $meta, null);
        }
    }

Usage Example

Example #1
0
File: cms.php Project: sphido/cms
 function __invoke($method, $path, $cms)
 {
     $this->cms = $cms = $this;
     // include prepend PHP file first
     is_file($php = \dir\content($path . '/index.php')) ? include_once $php : null || is_file($php = \dir\content($path . '.php')) ? include_once $php : null;
     // search page (html, md, latte, phtml)
     $this->page = Page::fromPath(\dir\content() . '/' . $path, (array) config()->meta);
     // include functions.php from $path and working directory
     is_file($php = \dir\content($path . '/functions.php')) ? include_once $php : null;
     is_file(getcwd() . '/functions.php') ? include_once getcwd() . '/functions.php' : null;
     print $this->page ? $this->render() : \route\error(404, $method, $path, $this);
 }