本文整理汇总了PHP中Less_Cache::prefix_vars方法的典型用法代码示例。如果您正苦于以下问题:PHP Less_Cache::prefix_vars方法的具体用法?PHP Less_Cache::prefix_vars怎么用?PHP Less_Cache::prefix_vars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Less_Cache
的用法示例。
在下文中一共展示了Less_Cache::prefix_vars方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Get
public static function Get($less_files, $parser_options = array(), $modify_vars = array()) {
if (isset($parser_options['cache_dir'])) {
Less_Cache::$cache_dir = $parser_options['cache_dir'];
}if (empty(Less_Cache::$cache_dir)) {
throw new Exception('cache_dir not set');
}if (isset($parser_options['prefix'])) {
Less_Cache::$prefix = $parser_options['prefix'];
}if (isset($parser_options['prefix_vars'])) {
Less_Cache::$prefix_vars = $parser_options['prefix_vars'];
}if (empty(Less_Cache::$prefix_vars)) {
throw new Exception('prefix_vars not set');
}self::CheckCacheDir();
$less_files = (array) $less_files;
if (!empty($modify_vars)) {
$lessvars = Less_Parser::serializeVars($modify_vars);
$vars_file = Less_Cache::$cache_dir . Less_Cache::$prefix_vars . sha1($lessvars) . '.less';
if (!file_exists($vars_file)) {
file_put_contents($vars_file, $lessvars);
}$less_files+=array($vars_file => '/');
}$hash = md5(json_encode($less_files));
$list_file = Less_Cache::$cache_dir . $hash . '.list';
if (!isset($parser_options['use_cache']) || $parser_options['use_cache'] === true) {
if (file_exists($list_file)) {
self::ListFiles($list_file, $list, $cached_name);
$compiled_name = self::CompiledName($list);
if (!$cached_name || $cached_name === $compiled_name) {
$output_file = self::OutputFile($compiled_name, $parser_options);
if ($output_file && file_exists($output_file)) {
@touch($list_file);
return basename($output_file);
}
}
}
}$compiled = self::Cache($less_files, $parser_options);
if (!$compiled) {
return false;
}$compiled_name = self::CompiledName($less_files);
$output_file = self::OutputFile($compiled_name, $parser_options);
$list = $less_files;
$list[] = $compiled_name;
$cache = implode("\n", $list);
file_put_contents($list_file, $cache);
$compiled = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $compiled);
file_put_contents($output_file, $compiled);
self::CleanCache();
return basename($output_file);
}
示例2: Get
/**
* Save and reuse the results of compiled less files.
* The first call to Get() will generate css and save it.
* Subsequent calls to Get() with the same arguments will return the same css filename
*
* @param array $less_files Array of .less files to compile
* @param array $parser_options Array of compiler options
* @param array $modify_vars Array of variables
* @return string Name of the css file
*/
public static function Get($less_files, $parser_options = array(), $modify_vars = array())
{
//check $cache_dir
if (isset($parser_options['cache_dir'])) {
Less_Cache::$cache_dir = $parser_options['cache_dir'];
}
if (empty(Less_Cache::$cache_dir)) {
throw new Exception('cache_dir not set');
}
if (isset($parser_options['prefix'])) {
Less_Cache::$prefix = $parser_options['prefix'];
}
if (empty(Less_Cache::$prefix)) {
throw new Exception('prefix not set');
}
if (isset($parser_options['prefix_vars'])) {
Less_Cache::$prefix_vars = $parser_options['prefix_vars'];
}
if (empty(Less_Cache::$prefix_vars)) {
throw new Exception('prefix_vars not set');
}
self::CheckCacheDir();
$less_files = (array) $less_files;
//create a file for variables
if (!empty($modify_vars)) {
$lessvars = Less_Parser::serializeVars($modify_vars);
$vars_file = Less_Cache::$cache_dir . Less_Cache::$prefix_vars . sha1($lessvars) . '.less';
if (!file_exists($vars_file)) {
file_put_contents($vars_file, $lessvars);
}
$less_files += array($vars_file => '/');
}
// generate name for compiled css file
$hash = md5(json_encode($less_files));
$list_file = Less_Cache::$cache_dir . Less_Cache::$prefix . $hash . '.list';
// check cached content
if (!isset($parser_options['use_cache']) || $parser_options['use_cache'] === true) {
if (file_exists($list_file)) {
self::ListFiles($list_file, $list, $cached_name);
$compiled_name = self::CompiledName($list, $hash);
// if $cached_name is the same as the $compiled name, don't regenerate
if (!$cached_name || $cached_name === $compiled_name) {
$output_file = self::OutputFile($compiled_name, $parser_options);
if ($output_file && file_exists($output_file)) {
@touch($list_file);
return basename($output_file);
// for backwards compatibility, we just return the name of the file
}
}
}
}
$compiled = self::Cache($less_files, $parser_options);
if (!$compiled) {
return false;
}
$compiled_name = self::CompiledName($less_files, $hash);
$output_file = self::OutputFile($compiled_name, $parser_options);
//save the file list
$list = $less_files;
$list[] = $compiled_name;
$cache = implode("\n", $list);
file_put_contents($list_file, $cache);
//save the css
file_put_contents($output_file, $compiled);
//clean up
self::CleanCache();
return basename($output_file);
}
示例3: Get
/**
* Save and reuse the results of compiled less files.
* The first call to Get() will generate css and save it.
* Subsequent calls to Get() with the same arguments will return the same css filename
*
* @param array $less_files Array of .less files to compile
* @param array $parser_options Array of compiler options
* @param array $modify_vars Array of variables
* @return string Name of the css file
*/
public static function Get($less_files, $parser_options = array(), $modify_vars = array())
{
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
global $wp_filesystem;
//check $cache_dir
if (isset($parser_options['cache_dir'])) {
Less_Cache::$cache_dir = $parser_options['cache_dir'];
}
if (empty(Less_Cache::$cache_dir)) {
throw new Exception('cache_dir not set');
}
if (isset($parser_options['prefix'])) {
Less_Cache::$prefix = $parser_options['prefix'];
}
if (empty(Less_Cache::$prefix)) {
throw new Exception('prefix not set');
}
if (isset($parser_options['prefix_vars'])) {
Less_Cache::$prefix_vars = $parser_options['prefix_vars'];
}
if (empty(Less_Cache::$prefix_vars)) {
throw new Exception('prefix_vars not set');
}
self::CheckCacheDir();
$less_files = (array) $less_files;
//create a file for variables
if (!empty($modify_vars)) {
$lessvars = Less_Parser::serializeVars($modify_vars);
$vars_file = Less_Cache::$cache_dir . Less_Cache::$prefix_vars . sha1($lessvars) . '.less';
if (!file_exists($vars_file)) {
$wp_filesystem->put_contents($vars_file, $lessvars, FS_CHMOD_FILE);
}
$less_files += array($vars_file => '/');
}
// generate name for compiled css file
$hash = md5(json_encode($less_files));
$list_file = Less_Cache::$cache_dir . Less_Cache::$prefix . $hash . '.list';
// check cached content
if (!isset($parser_options['use_cache']) || $parser_options['use_cache'] === true) {
if (file_exists($list_file)) {
self::ListFiles($list_file, $list, $cached_name);
$compiled_name = self::CompiledName($list);
// if $cached_name != $compiled_name, we know we need to recompile
if (!$cached_name || $cached_name === $compiled_name) {
$output_file = self::OutputFile($compiled_name, $parser_options);
if ($output_file && file_exists($output_file)) {
@touch($list_file);
return wp_basename($output_file);
// for backwards compatibility, we just return the name of the file
}
}
}
}
$compiled = self::Cache($less_files, $parser_options);
if (!$compiled) {
return false;
}
$compiled_name = self::CompiledName($less_files);
$output_file = self::OutputFile($compiled_name, $parser_options);
//save the file list
$list = $less_files;
$list[] = $compiled_name;
$cache = implode("\n", $list);
$wp_filesystem->put_contents($list_file, $cache, FS_CHMOD_FILE);
//save the css
$wp_filesystem->put_contents($output_file, $compiled, FS_CHMOD_FILE);
//clean up
self::CleanCache();
return wp_basename($output_file);
}