view, PATHINFO_EXTENSION); if ($ext) { // view is filename return "{$this->location}{$this->view}"; } $str = "{$this->location}{$this->view}.{$this->extension}"; if ($this->extension === null) { // try to guess from filesystem $files = glob("{$this->location}{$this->view}.*"); if (count($files) === 1) { $str = $files[0]; } else { $str = "{$this->location}{$this->view}.?"; } } return $str; } /** * Get a component from the path and location * * @param string $path Full file path * @param string $location Base location of view * * @return ViewComponent */ public static function fromPaths($path, $location) { $component = new self(); $component->location = $location; // cut location off $file = substr($path, strlen($location)); $component->file = $file; $basename = basename($file); $period = strpos($basename, '.'); if ($period === false) { // file with no extension? shouldn't happen $component->view = $file; $component->extension = ''; } else { $cut_off_end = strlen($basename) - $period; $component->view = substr($file, 0, -$cut_off_end); $component->extension = substr($basename, $period + 1); } return $component; } }