/** * Loads a view and set it into blocks * @param string $file * @param string $view_path custom view path */ public function load($file, $view_path = null) { // is the first (main) view to load? if (empty($this->blocks)) { // set the content type $this->set_content_type($file); } // get the blocks from cache? $file_path = $this->get_view_file_path($file, $view_path); $cache_key = str_replace(DIRECTORY_SEPARATOR, '-', $file_path); $blocks = $this->cache->get_by_file($cache_key, $file_path); // do we have cached content? if (empty($blocks)) { // get the file contents $template = $this->get_file_content($file_path); // get the blocks from the template content $blocks = $this->get_blocks($template, $file); // set the blocks on cache $this->cache->set($cache_key, $blocks); } $blocks = $this->get_block_l10n($blocks, $file); // set the blocks $this->blocks = array_merge($this->blocks, $blocks); }
/** * Set the cache handler * @param array $options */ private function set_cache(array $options) { // set the cache instance $this->cache = Cache::get_instance('default', $options); }
/** * Retrieves and parse the language strings from the l10n string files * Sets the strings on cache * @param string $controller * @param string $method * @param array $strings_paths * @return array */ private static function get_strings($controller, $method, array $strings_paths) { $global_strings = []; $controller_strings = []; $method_strings = []; foreach ($strings_paths as $strings_path) { // get the strings data $strings_data = parse_ini_file($strings_path, true); if ($strings_data) { // set the global, controller and method strings $global_strings = array_merge($global_strings, self::get_section_strings($strings_data, 'global')); $controller_strings = array_merge($controller_strings, self::get_section_strings($strings_data, $controller)); $method_strings = array_merge($method_strings, self::get_section_strings($strings_data, $controller . '-' . $method)); } } // merge the strings content $strings = array_merge($global_strings, $controller_strings, $method_strings); // set the strings in cache Cache::get_instance()->set(self::$cache_key, $strings); return $strings; }