/** * Test case method */ public function testAddIncludePath3() { $old = Enlight_Loader::addIncludePath('.', Enlight_Loader::POSITION_REMOVE); $new = Enlight_Loader::explodeIncludePath(); $found = array_search('.', $new); Enlight_Loader::setIncludePath($old); $this->assertFalse($found); }
function smarty_function_booster(array $params, Smarty_Internal_Template $template) { $root = $template; $type = isset($params['type']) ? $params['type'] : null; $media = isset($params['media']) ? $params['media'] : null; $src = isset($params['src']) ? $params['src'] : null; $output = isset($params['output']); // sanity checks if ($type !== 'css' && $type !== 'js') { throw new Exception('{booster type="css|js"} - unknown type "' . $type . '"'); } // TODO: allow arrays of src if (!$output && !$src) { throw new Exception('{booster src="/some/file.css"} - invalid src "' . $src . '"'); } // get all available templates $dirs = (array) $root->smarty->getTemplateDir(); $dirs += Enlight_Loader::explodeIncludePath(); // try to find the file on the filesystem foreach ($dirs as $dir) { $templateDir = str_ireplace(DOCPATH, '', $dir); if (file_exists($dir . $src)) { $src = $templateDir . $src; break; } } $filepath = DOCPATH . $src; if (!file_exists($filepath)) { throw new Exception('{booster src="' . $src . '"} file not found at "' . $filepath . '"'); } // store stuff in the root template (NOT Smarty)! while ($root->parent && $root->parent instanceof Smarty_Internal_Template) { $root = $root->parent; } // create booster $booster = $root->getTemplateVars('__booster'); if (!$booster) { $booster = new Booster(); // TODO: import options from somewhere $booster->js_minify = true; $booster->css_totalparts = 1; $booster->booster_cachedir = '../../../cache/templates'; $root->assign('__booster', $booster); } // create cache // Note: would've liked a reference, but can't count on getTemplateVars() allowing to return by ref :( $cache = $root->getTemplateVars('__booster_cache'); if (!$cache) { $cache = array('css' => array(), 'js' => array()); } // make sure paths are relative to the booster directory // they are to be provided absolute from the doc root // booster is supposed to be in the doc root // so prepending .. should work fine $src = '../../../' . $src; $result = ''; if ($output) { // We're using mod_rewrite but the booster builds up an strange // path if mod_rewrite is on, so we set it manually to false $booster->mod_rewrite = false; if ($type == 'css') { if (empty($cache['css'][$media])) { return $result; } $booster->css_source = $cache['css'][$media]; $cache['css'][$media] = array(); $booster->css_media = $media; $result = $booster->css_markup(); } else { $booster->js_source = $cache['js']; $cache['js'] = array(); $result = $booster->js_markup(); } } else { if ($type == 'css') { $cache['css'][$media][] = $src; } else { $cache['js'][] = $src; } } $root->assign('__booster_cache', $cache); return $result; }