本文整理汇总了PHP中Less_Cache::cache_dir方法的典型用法代码示例。如果您正苦于以下问题:PHP Less_Cache::cache_dir方法的具体用法?PHP Less_Cache::cache_dir怎么用?PHP Less_Cache::cache_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Less_Cache
的用法示例。
在下文中一共展示了Less_Cache::cache_dir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadStyles
public static function loadStyles() {
require_once ($_SERVER['DOCUMENT_ROOT'] . '/inc/less/Less.php');
Less_Cache::$cache_dir = $_SERVER['DOCUMENT_ROOT'] . '/css/cache/';
$files[$_SERVER['DOCUMENT_ROOT'] . '/css/style.less'] = '/css/';
$css_file_name = Less_Cache::Get($files);
self::$styles = '<link rel="stylesheet" type="text/css" href="/css/cache/' . $css_file_name . '">';
}
示例2: Get
public static function Get($less_files, $parser_options = array())
{
//check $cache_dir
if (empty(self::$cache_dir)) {
throw new Exception('cache_dir not set');
return false;
}
self::$cache_dir = str_replace('\\', '/', self::$cache_dir);
self::$cache_dir = rtrim(self::$cache_dir, '/') . '/';
if (!is_dir(self::$cache_dir)) {
throw new Exception('cache_dir does not exist');
return false;
}
// generate name for compiled css file
$less_files = (array) $less_files;
$hash = md5(json_encode($less_files));
$list_file = self::$cache_dir . 'lessphp_' . $hash . '.list';
// check cached content
$compiled_file = false;
$less_cache = false;
if (file_exists($list_file)) {
//get info about the list file
$compiled_name = self::CompiledName($hash, $list_file);
$compiled_file = self::$cache_dir . $compiled_name;
//check modified time of all included files
if (file_exists($compiled_file)) {
$list = explode("\n", file_get_contents($list_file));
$list_updated = filemtime($list_file);
foreach ($list as $file) {
if (!file_exists($file) || filemtime($file) > $list_updated) {
$compiled_file = false;
break;
}
}
// return relative path if we don't need to regenerate
if ($compiled_file) {
//touch the files to extend the cache
touch($list_file);
touch($compiled_file);
return $compiled_name;
}
}
}
$compiled = self::Cache($less_files, $parser_options);
if (!$compiled) {
return false;
}
//save the cache
$cache = implode("\n", $less_files);
file_put_contents($list_file, $cache);
//save the css
$compiled_name = self::CompiledName($hash, $list_file);
file_put_contents(self::$cache_dir . $compiled_name, $compiled);
//clean up
self::CleanCache();
return $compiled_name;
}
示例3: __invoke
/**
*
* @param string $lessFile
* @param string $id
* @return string
*/
public function __invoke($lessFile, $id = "")
{
// less options
$options = array('compress' => $this->options->getMinify());
// file to cache
$to_cache = array($lessFile => $this->view->basePath(""));
\Less_Cache::$cache_dir = $this->options->getCacheFolder();
$css_file_name = \Less_Cache::Get($to_cache, $options);
if ($id == "") {
$id = substr($css_file_name, 0, -4);
}
return "<link type='text/css' id='" . $id . "' rel='stylesheet' href='" . $this->options->getCacheFolderUrl() . $css_file_name . "' />";
}
示例4: stormbringer_preprocessor
function stormbringer_preprocessor() {
$preprocessor = get_theme_mod('bootstrap_preprocessor', true);
$cssfile = 'css/styles.css';
if ( $preprocessor === 'less' ) {
if ( ! is_admin() ) {
if ( current_user_can( 'administrator' ) && $_GET['lesscompile'] != '1' ) {
}
else {
$to_cache = array( STYLESHEETPATH . '/less/application.less' => '' );
Less_Cache::$cache_dir = STYLESHEETPATH . '/css/';
$css_file_name = Less_Cache::Get( $to_cache );
wp_register_style( 'theme', get_stylesheet_directory_uri() . '/'.$cssfile, array(), null, null );
wp_enqueue_style( 'theme' );
}
}
}
if ( $preprocessor === 'scss' || $preprocessor == 1) {
if ( ! is_admin() ) {
if ( current_user_can( 'administrator' ) || $_GET['scsscompile'] == '1' ) {
wp_register_style( 'theme', get_stylesheet_directory_uri() . '/css/styles.css', array(), null, null );
wp_enqueue_style( 'theme' );
} else {
$cssfile = 'css/styles.min.css';
$grunt_assets = get_theme_mod('grunt_assets');
//if(isset($grunt_assets[$cssfile])) {
// $cssfile = $grunt_assets[$cssfile];
//}
wp_register_style( 'theme', get_stylesheet_directory_uri() . '/'.$cssfile, array(), null, null );
wp_enqueue_style( 'theme' );
}
}
}
}
示例5: SetCacheDir
public static function SetCacheDir($dir)
{
Less_Cache::$cache_dir = $dir;
}
示例6: SetCacheDir
public static function SetCacheDir($dir)
{
Less_Cache::$cache_dir = null;
if (is_string($dir)) {
if (!file_exists($dir)) {
if (!mkdir($dir)) {
throw new Less_Exception_Parser('Less.php cache directory couldn\'t be created: ' . $dir);
}
} elseif (!is_dir($dir)) {
throw new Less_Exception_Parser('Less.php cache directory doesn\'t exist: ' . $dir);
} elseif (!is_writable($dir)) {
throw new Less_Exception_Parser('Less.php cache directory isn\'t writable: ' . $dir);
}
$dir = str_replace('\\', '/', $dir);
Less_Cache::$cache_dir = rtrim($dir, '/') . '/';
}
return true;
}
示例7: array
<?php
require __DIR__ . '/../vendor/autoload.php';
$parser = new Less_Parser();
$cacheDir = __DIR__ . '/../var/cache/less';
@mkdir($cacheDir, 0755, true);
$compileItems = [__DIR__ . "/../data/less/bootstrap/bootstrap.less" => __DIR__ . '/../public/css/bootstrap.css', __DIR__ . "/../data/less/bootstrap/theme.less" => __DIR__ . '/../public/css/bootstrap-theme.css'];
foreach ($compileItems as $input => $output) {
$cacheSetting = array($input => '/mysite/');
Less_Cache::$cache_dir = $cacheDir;
$cssFileName = Less_Cache::Get($cacheSetting);
echo "{$cssFileName} \n";
$compiled = file_get_contents($cacheDir . '/' . $cssFileName);
file_put_contents($output, $compiled);
}
示例8: getCachedFile
/**
* Generates and Gets the Cached files
*
* This will generated a compiled less file into css format
* but it will cache it so that it doesnt happen unless the file has changed
*
* @param string $dir The directory housing the less files
* @param string $uri_root The uri root of the web request
* @param array $variables Array of variables to override
* @return string the CSS filename
*/
public function getCachedFile($dir, $uri_root = '', $variables = array())
{
if (!file_exists($dir . '/cache')) {
if (!mkdir($dir . '/cache')) {
die_freepbx(sprintf(_('Can not create cache folder at %s/cache. Please run (from the CLI): %s'), $dir, 'amportal chown'));
}
}
\Less_Cache::$cache_dir = $dir . '/cache';
$files = array();
$basename = basename($dir);
try {
if (file_exists($dir . "/bootstrap.less")) {
$files = array($dir . "/bootstrap.less" => $uri_root);
$filename = \Less_Cache::Get($files, array('compress' => true), $variables);
} elseif (file_exists($dir . "/" . $basename . ".less")) {
$files = array($dir . "/" . $basename . ".less" => $uri_root);
$filename = \Less_Cache::Get($files, array('compress' => true), $variables);
} else {
//load them all randomly. Probably in alpha order
foreach (glob($dir . "/*.less") as $file) {
$files[$file] = $uri_root;
}
uksort($files, "strcmp");
$filename = \Less_Cache::Get($files, array('compress' => true), $variables);
}
} catch (\Exception $e) {
die_freepbx(sprintf(_('Can not write to cache folder at %s/cache. Please run (from the CLI): %s'), $dir, 'amportal chown'));
}
return $filename;
}
示例9: dirname
<?php
require 'Cache.php';
Less_Cache::$cache_dir = dirname(__FILE__) . '/cache';
$files = array();
$files[dirname(__FILE__) . '/less/bootstrap.less'] = '/';
//$files['teste.less'] = '/mysite/custom/';
$css_file_name = Less_Cache::Get($files);
//echo '<link rel="stylesheet" type="text/css" href="/_testes/less.php/cache/'.$css_file_name.'">';
header('Content-Type: css/text');
header('Location: cache/' . $css_file_name . '');
示例10: testLessJsCssGeneration
public function testLessJsCssGeneration($dir, $less, $css, $map)
{
global $obj_buffer;
$options = array();
$options['compress'] = $this->compress;
//$options['relativeUrls'] = true;
//$options['cache_dir'] = $this->cache_dir;
//$options['cache_method'] = 'php';
//$options['urlArgs'] = '424242';
$this->files_tested++;
$matched = false;
$basename = basename($less);
$basename = substr($basename, 0, -5);
//remove .less extension
$file_less = $dir . $less;
$file_uri = $this->AbsoluteToRelative(dirname($file_less));
$file_sourcemap = false;
$file_css = false;
echo '<a class="filename" href="?dir=' . rawurlencode($this->dir) . '&file=' . rawurlencode($basename) . '">File: ' . $basename . '</a>';
if (!file_exists($file_less)) {
echo '<b>LESS file missing: ' . $file_less . '</b>';
return false;
}
//css or map
if ($css) {
$file_css = $dir . $css;
$file_expected = $this->TranslateFile($file_css, 'expected', 'css');
if (!file_exists($file_css)) {
echo '<b>CSS file missing: ' . $file_css . '</b>';
return false;
}
} elseif ($map) {
$file_sourcemap = $dir . $map;
$file_expected = $this->TranslateFile($file_sourcemap, 'expected', 'map');
if (!file_exists($file_sourcemap)) {
echo '<b>Sourcemap file missing: ' . $file_sourcemap . '</b>';
return false;
}
} else {
echo '<b>Unknown comparison file</b>';
return false;
}
//generate the sourcemap
if (file_exists($file_sourcemap)) {
$generated_map = $this->cache_dir . '/' . $basename . '.map';
$options['sourceMap'] = true;
$options['sourceMapBasepath'] = $dir;
$options['sourceMapWriteTo'] = $generated_map;
$options['sourceMapURL'] = $this->AbsoluteToRelative($generated_map);
}
//example, but not very functional import callback
/*
$options['import_callback'] = 'callback';
if( !function_exists('callback') ){
function callback($evald){
$evaldPath = $evald->getPath();
msg('evaldpath: '.$evaldPath);
}
}
*/
$compiled = '';
try {
/**
* Less_Cache Testing
*/
Less_Cache::$cache_dir = $this->cache_dir;
//$cached_css_file = Less_Cache::Regen( array($file_less=>'') );
//$options['output'] = md5($file_less).'.css';
$cached_css_file = Less_Cache::Get(array($file_less => ''), $options);
$compiled = file_get_contents($this->cache_dir . '/' . $cached_css_file);
/*
$parser = new Less_Parser( $options );
$parser->parseFile( $file_less ); //$file_uri
$compiled = $parser->getCss();
*/
//$parser = new Less_Parser( $options );
//$less_content = file_get_contents( $file_less );
//$parser->parse( $less_content );
//$compiled = $parser->getCss();
//$parser = new lessc();
//$compiled = $parser->compileFile($file_less);
//$parser = new lessc();
//$compiled = $parser->compile(file_get_contents($file_less));
} catch (Exception $e) {
$compiled = $e->getMessage();
}
//sourcemap comparison
if ($file_sourcemap) {
//$expected = file_get_contents($generated_map);
//$this->SaveExpected($file_expected, $expected);
$generated_map = $this->ComparableSourceMap($generated_map);
$file_sourcemap = $this->ComparableSourceMap($file_sourcemap);
$expected_map = '';
if (file_exists($file_expected)) {
$expected_map = $this->ComparableSourceMap($file_expected);
}
$matched = $this->CompareFiles($generated_map, $file_sourcemap, $expected_map);
if (isset($_GET['file'])) {
$this->PHPDiff($generated_map, $file_sourcemap, true);
$this->ObjBuffer();
//.........这里部分代码省略.........
示例11:
<?php
require 'inc/less.php/Cache.php';
Less_Cache::$cache_dir = 'css';
$boostrap = Less_Cache::Get(['less/bootstrap/bootstrap.less' => 'bootstrap']);
$styles = Less_Cache::Get(['less/styles.less' => 'css']);
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-COMPATIBLE" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="">
<title>Island-Fansub v3</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,700' rel='stylesheet'
type='text/css'>
<?php
echo '<link rel="stylesheet" type="text/css" href="css/' . $boostrap . '">';
?>
<link rel="stylesheet" type="text/css" href="css/linearIcons.css">
<link rel="stylesheet" type="text/css" href="css/ie10-viewport-bug-workaround.css">
<?php
echo '<link rel="stylesheet" type="text/css" href="css/' . $styles . '">';
?>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
示例12: file_get_contents
<?php
error_reporting(E_ALL);
require 'Cache.php';
Less_Cache::$cache_dir = 'cache';
$files = array();
$files['custom.less'] = '/mysite/bootstrap/';
$css_file_name = Less_Cache::Get($files);
header("Content-Type: text/css");
echo file_get_contents('cache/' . $css_file_name);
示例13: getGlobalLess
/**
* Generate all CSS from LESS
* @param bool $force Whether to forcefully regenerate all CSS from LESS
*/
public function getGlobalLess($force = false)
{
$cache = dirname(__DIR__) . '/assets/css/compiled/modules';
if (!file_exists($cache) && !mkdir($cache, 0777, true)) {
die('Can Not Create Cache Folder at ' . $cache);
}
if ($force) {
foreach (glob($cache . '/lessphp_*') as $f) {
unlink($f);
}
}
$amods = array_merge($this->defaultModules, array_keys($this->freepbxActiveModules));
\Less_Cache::$cache_dir = $cache;
$files = array();
foreach (glob(dirname(__DIR__) . "/modules/*", GLOB_ONLYDIR) as $module) {
$mod = basename($module);
if (file_exists($module . '/' . $mod . '.class.php')) {
$module = ucfirst(strtolower($mod));
if (!in_array(strtolower($mod), $amods)) {
continue;
}
$dir = dirname(__DIR__) . "/modules/" . $module . "/assets/less";
if (is_dir($dir) && file_exists($dir . '/bootstrap.less')) {
$files[$dir . "/bootstrap.less"] = '../../../../modules/' . ucfirst($module) . '/assets';
}
}
}
$css_file_name = \Less_Cache::Get($files, array('compress' => true));
return $css_file_name;
}
示例14: SetCacheDir
/**
* @deprecated 1.5.1.2
*
*/
public function SetCacheDir($dir)
{
if (!file_exists($dir)) {
if (mkdir($dir)) {
return true;
}
throw new Less_Exception_Parser('Less.php cache directory couldn\'t be created: ' . $dir);
} elseif (!is_dir($dir)) {
throw new Less_Exception_Parser('Less.php cache directory doesn\'t exist: ' . $dir);
} elseif (!is_writable($dir)) {
throw new Less_Exception_Parser('Less.php cache directory isn\'t writable: ' . $dir);
} else {
$dir = self::WinPath($dir);
Less_Cache::$cache_dir = rtrim($dir, '/') . '/';
return true;
}
}
示例15: getCachedFile
/**
* Generates and Gets the Cached files
*
* This will generated a compiled less file into css format
* but it will cache it so that it doesnt happen unless the file has changed
*
* @param string $dir The directory housing the less files
* @param string $uri_root The uri root of the web request
* @param array $variables Array of variables to override
* @return string the CSS filename
*/
public function getCachedFile($dir, $uri_root = '', $variables = array())
{
if (!file_exists($dir . '/cache')) {
// Explicitly don't trigger an E_WARNING, as PHP doesn't tell you what
// it was trying to mkdir, so the error is useless.
if (!@mkdir($dir . '/cache')) {
die_freepbx(sprintf(_('Can not create the LESS cache folder at %s. Please run (from the CLI): %s'), $dir . '/cache', 'fwconsole chown'));
}
$ampowner = $this->FreePBX->Config->get('AMPASTERISKWEBUSER');
$ampgroup = $ampowner != $this->FreePBX->Config->get('AMPASTERISKUSER') ? $this->FreePBX->Config->get('AMPASTERISKGROUP') : $ampowner;
chown($dir . '/cache', $ampowner);
chgrp($dir . '/cache', $ampgroup);
}
if (!is_readable($dir)) {
die_freepbx(sprintf(_('Can not read from the LESS folder at %s. Please run (from the CLI): %s'), $dir, 'fwconsole chown'));
}
if (!is_readable($dir . '/cache') || !is_writable($dir . '/cache')) {
die_freepbx(sprintf(_('Can not write to the LESS cache folder at %s. Please run (from the CLI): %s'), $dir . '/cache', 'fwconsole chown'));
}
\Less_Cache::$cache_dir = $dir . '/cache';
$files = array();
$basename = basename($dir);
try {
if (file_exists($dir . "/bootstrap.less")) {
$files = array($dir . "/bootstrap.less" => $uri_root);
$filename = \Less_Cache::Get($files, array('compress' => true), $variables);
} elseif (file_exists($dir . "/" . $basename . ".less")) {
$files = array($dir . "/" . $basename . ".less" => $uri_root);
$filename = \Less_Cache::Get($files, array('compress' => true), $variables);
} else {
//load them all randomly. Probably in alpha order
foreach (glob($dir . "/*.less") as $file) {
$files[$file] = $uri_root;
}
uksort($files, "strcmp");
$filename = \Less_Cache::Get($files, array('compress' => true), $variables);
}
} catch (\Exception $e) {
die_freepbx(sprintf(_('Error with the templating engine: %s'), $e->getMessage()));
}
return $filename;
}