/** * Get the path to a view file by looking in many places * * @param String $file the view file to find by searching the views folders * @param Array $options an optional array of options (e.g. "must_find") * @return String the path to the view file */ protected function get_view_path($file, $options = array()) { // Read any options that were passed, e.g. extension $must_find = array_key($options, 'must_find', FALSE); $has_slash = strpos($file, '/') !== FALSE; $lang = array_key($options, 'lang', $this->lang); $folder = array_key($options, Symbol::FOLDER, $this->folder); $type = array_key($options, 'type', $this->content_type); $ext = array_key($options, 'ext', DEFAULT_EXTENSION); // Create an array of paths to look for a view file $lang_folder = 'views/' . $lang . '/'; $paths = array(); if ($type !== DEFAULT_CONTENT_TYPE) { $paths[] = "{$lang_folder}{$folder}/{$file}.{$type}{$ext}"; } $paths[] = $lang_folder . $folder . '/' . $file . $ext; if ($has_slash) { $paths[] = $lang_folder . '/' . $file . $ext; } $paths[] = $lang_folder . DEFAULT_FOLDER . '/' . $file . $ext; if (!$must_find) { $paths[] = $lang_folder . DEFAULT_FOLDER . '/' . FILE_NOT_FOUND . DEFAULT_EXTENSION; } // Return the first path we found in the path array foreach ($paths as $path) { if (file_found($path)) { return $path; } } return NULL; // path not found }
/** * Load some PHP files with "require_once", only if they are not already loaded * * @param String $dir the directory from which to load the files * @param Array $files a list of files to load from the directory * @param Boolean $is_mock whether to load a mock version of the file * @return Array a list of the files that were loaded with "require_once" */ function load_files($dir, $files, $is_mock = FALSE) { static $loaded = array(); // to skip loading files that were loaded before $required_files = array(); // to return a list of files that are now loaded foreach ($files as $file) { $path = $dir . '/' . $file . '.php'; if (array_key($loaded, $path)) { continue; } $real_path = $is_mock ? $dir . '/mocks/' . $file . '.php' : $path; if (!file_found($real_path)) { throw new Exception("File \"{$real_path}\" not found"); } require_once $real_path; $loaded[$path] = TRUE; $required_files[] = $file; } return $required_files; }