本文整理汇总了PHP中lessc::cachedCompile方法的典型用法代码示例。如果您正苦于以下问题:PHP lessc::cachedCompile方法的具体用法?PHP lessc::cachedCompile怎么用?PHP lessc::cachedCompile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lessc
的用法示例。
在下文中一共展示了lessc::cachedCompile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: auto_less_compile
function auto_less_compile($inputFile, $outputFile)
{
// load the cache
$cacheFile = $inputFile . ".cache";
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $inputFile;
}
// custom formatter
$formatter = new lessc_formatter_classic();
$formatter->indentChar = "\t";
$less = new lessc();
$less->setFormatter($formatter);
try {
// create a new cache object, and compile
$newCache = $less->cachedCompile($cache);
// the next time we run, write only if it has updated
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
file_put_contents($cacheFile, serialize($newCache));
file_put_contents($outputFile, $newCache['compiled']);
}
} catch (Exception $ex) {
echo "lessphp fatal error: " . $ex->getMessage();
}
}
示例2: parse
/**
* Parse a Less file to CSS
*/
public function parse($src, $dst, $options)
{
$this->auto = isset($options['auto']) ? $options['auto'] : $this->auto;
try {
if ($this->auto) {
/* @var FileCache $cacheMgr */
$cacheMgr = Yii::createObject('yii\\caching\\FileCache');
$cacheMgr->init();
$cacheId = 'less#' . $dst;
$cache = $cacheMgr->get($cacheId);
if ($cache === false || @filemtime($dst) < @filemtime($src)) {
$cache = $src;
}
$less = new \lessc();
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
$cacheMgr->set($cacheId, $newCache);
file_put_contents($dst, $newCache['compiled']);
}
} else {
$less = new \lessc();
$less->compileFile($src, $dst);
}
} catch (Exception $e) {
throw new Exception(__CLASS__ . ': Failed to compile less file : ' . $e->getMessage() . '.');
}
}
示例3: lessCompile
/**
* @param string $src
* @return string
*/
public function lessCompile($src)
{
$path = $this->lessCompiledPath . DIRECTORY_SEPARATOR . basename($src, '.less') . '.css';
$lessCompile = false;
if (!$this->lessForceCompile && $this->lessCompile) {
$lessFiles = $this->_cacheGet('EAssetManager-less-updated-' . $src);
if ($lessFiles && is_array($lessFiles)) {
foreach ($lessFiles as $_file => $_time) {
if (filemtime($_file) != $_time) {
$lessCompile = true;
break;
}
}
} else {
$lessCompile = true;
}
unset($lessFiles);
}
if (!file_exists($path) || $lessCompile || $this->lessForceCompile) {
if (!$this->_lessc) {
$this->_lessc = new lessc();
}
$this->_lessc->setFormatter($this->lessFormatter);
$lessCache = $this->_lessc->cachedCompile($src);
file_put_contents($path, $lessCache['compiled'], LOCK_EX);
$this->_cacheSet('EAssetManager-less-updated-' . $src, $lessCache['files']);
}
return $path;
}
示例4: doProcess
protected function doProcess($inputPath, $outputPath)
{
$this->ensureInitialized();
if ($this->jsToolOptions === false) {
$less = new \lessc();
if ($this->pieCrust->isCachingEnabled()) {
$cacheUri = 'less/' . sha1($inputPath);
$cacheData = $this->readCacheData($cacheUri);
if ($cacheData) {
$lastUpdated = $cacheData['updated'];
} else {
$lastUpdated = false;
$cacheData = $inputPath;
}
$cacheData = $less->cachedCompile($cacheData);
$this->writeCacheData($cacheUri, $cacheData);
if (!$lastUpdated || $cacheData['updated'] > $lastUpdated) {
file_put_contents($outputPath, $cacheData['compiled']);
}
} else {
$less->compileFile($inputPath, $outputPath);
}
} else {
$exe = $this->jsToolOptions['bin'];
$options = $this->jsToolOptions['options'];
$cmd = "{$exe} {$options} \"{$inputPath}\" \"{$outputPath}\"";
$this->logger->debug('$> ' . $cmd);
shell_exec($cmd);
}
}
示例5: compileLess
public function compileLess($inputFile, $outputFile)
{
if (!class_exists('lessc')) {
require_once KPATH_FRAMEWORK . '/external/lessc/lessc.php';
}
// Load the cache.
$cacheDir = JPATH_CACHE . '/kunena';
if (!is_dir($cacheDir)) {
KunenaFolder::create($cacheDir);
}
$cacheFile = "{$cacheDir}/kunena.bootstrap.{$inputFile}.cache";
if (is_file($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = KPATH_MEDIA . '/less/bootstrap/' . $inputFile;
}
$outputFile = KPATH_MEDIA . '/css/joomla25/' . $outputFile;
$less = new lessc();
//$less->setVariables($this->style_variables);
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache['updated'] > $cache['updated'] || !is_file($outputFile)) {
$cache = serialize($newCache);
KunenaFile::write($cacheFile, $cache);
KunenaFile::write($outputFile, $newCache['compiled']);
}
}
示例6: autoCompilerLess
function autoCompilerLess($params)
{
global $modx;
$inputFile = MODX_BASE_PATH . $params["input_less"];
$outputFile = MODX_BASE_PATH . $params["output_css"];
define("PHPLESS_CSS_PATH", dirname($outputFile) . "/");
define("PHPLESS_IMAGESIZE", 32);
if (!is_file(MODX_BASE_PATH . $params["input_less"])) {
return;
}
if (!class_exists('lessc')) {
include $params['less_path'] . 'lessc.inc.php';
}
if (!class_exists('DataUriLess')) {
include $params['less_path'] . 'class.datauriless.php';
}
$cacheFile = $inputFile . ".cache";
if (is_file($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $inputFile;
}
switch ($params['output_formating']) {
case 'lessjs':
case 'compressed':
$formatter = 'lessjs';
break;
case 'classic':
$formatter = $params['output_formating'];
break;
case 'tabing':
$formatter = new lessc_formatter_classic();
$formatter->indentChar = "\t";
break;
default:
$formatter = 'lessjs';
break;
}
$less = new lessc();
$less->setFormatter($formatter);
try {
$newCache = $less->cachedCompile($cache);
} catch (Exception $ex) {
$modx->logEvent(0, 3, $ex->getMessage(), $e->activePlugin);
}
if (!is_array($cache) || $newCache["updated"] > $cache["updated"] || !is_file($outputFile)) {
file_put_contents($cacheFile, serialize($newCache));
$datauri = new DataUriLess($newCache['compiled']);
$output_compile = $datauri->run();
if (@file_put_contents($outputFile, $output_compile)) {
//if($params["compiler_log"]==="true"){
$e =& $modx->Event;
$modx->logEvent($modx->toDateFormat(time() + $modx->config['server_offset_time']), 1, "less файл скомпилирован " . $modx->nicesize(filesize($outputFile)), $e->activePlugin);
//}
} else {
$modx->logEvent(0, 3, "Невозможно сохранить CSS файл", $e->activePlugin);
}
}
}
示例7: compile
/**
* Compiles a less css file. The the compiler will create a css file output.
*
* @param array $config Array of less compile configuration
*/
public function compile($config = array())
{
$config = new KConfig($config);
$config->append(array('parse_urls' => true, 'compress' => true, 'import' => array(), 'force' => false, 'output' => null, 'input' => null));
$less = new lessc();
$less->setPreserveComments(!$config->compress);
if ($config->compress) {
$less->setFormatter('compressed');
}
$config['import'] = $config['import'];
$less->setImportDir($config['import']);
$cache_file = JPATH_CACHE . '/less-' . md5($config->input);
if (file_exists($cache_file)) {
$cache = unserialize(file_get_contents($cache_file));
} else {
$cache = $config->input;
}
$force = $config->force;
//if output doesn't exsit then force compile
if (!is_readable($config->output)) {
$force = true;
}
//check if any of the import folder have changed or
//if yes then re-compile
if (is_array($cache)) {
foreach ($config['import'] as $path) {
if (is_readable($path) && filemtime($path) > $cache['updated']) {
$force = true;
break;
}
}
}
try {
$new_cache = $less->cachedCompile($cache, $force);
} catch (Exception $e) {
print $e->getMessage();
return;
}
if (!is_array($cache) || $new_cache['updated'] > $cache['updated']) {
if ($config->parse_urls) {
$new_cache['compiled'] = $this->_parseUrls($new_cache['compiled'], $config->import);
}
//store the cache
file_put_contents($cache_file, serialize($new_cache));
//store the compiled file
//create a directory if
if (!file_exists(dirname($config->output))) {
mkdir(dirname($config->output), 0755);
}
file_put_contents($config->output, $new_cache['compiled']);
}
}
示例8: parse
/**
* Parse a Less file to CSS
*/
public function parse($src, $dst, $options)
{
$this->auto = isset($options['auto']) ? $options['auto'] : $this->auto;
$variables = $this->variables;
$assetManager = Yii::$app->assetManager;
// Final url of the file being compiled
$assetUrl = substr($dst, strpos($assetManager->basePath, $assetManager->baseUrl));
$variables['published-url'] = '"' . $assetUrl . '"';
// Root for the published folder
$variables['published-base-url'] = '"/' . implode('/', array_slice(explode('/', ltrim($assetUrl, '/')), 0, 2)) . '"';
$less = new \lessc();
$less->setVariables($variables);
// Compressed setting
if ($this->compressed) {
$less->setFormatter('compressed');
}
\Less_Parser::$default_options['compress'] = $this->compressed;
\Less_Parser::$default_options['relativeUrls'] = $this->relativeUrls;
// Send out pre-compile event
$event = new \yii\base\Event();
$this->runtime = ['sourceFile' => $src, 'destinationFile' => $dst, 'compiler' => $less];
$event->sender = $this;
Event::trigger($this, self::EVENT_BEFORE_COMPILE, $event);
try {
if ($this->auto) {
/* @var FileCache $cacheMgr */
$cacheMgr = Yii::createObject('yii\\caching\\FileCache');
$cacheMgr->init();
$cacheId = 'less#' . $dst;
$cache = $cacheMgr->get($cacheId);
if ($cache === false || @filemtime($dst) < @filemtime($src)) {
$cache = $src;
}
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
$cacheMgr->set($cacheId, $newCache);
file_put_contents($dst, $newCache['compiled']);
}
} else {
$less->compileFile($src, $dst);
}
// If needed, respect the users configuration
if ($assetManager->fileMode !== null) {
@chmod($dst, $assetManager->fileMode);
}
unset($this->less);
} catch (\Exception $e) {
throw new \Exception(__CLASS__ . ': Failed to compile less file : ' . $e->getMessage() . '.');
}
}
示例9: less_css
function less_css($handle)
{
include DUDE_THEME_DIR . "/less/variables.php";
// output css file name
$css_path = DUDE_THEME_DIR . '/css/' . "{$handle}.css";
// automatically regenerate files if source's modified time has changed or vars have changed
try {
// initialise the parser
$less = new lessc();
// load the cache
$cache_path = DUDE_THEME_DIR . "/cache/{$handle}.css.cache";
if (file_exists($cache_path)) {
$cache = unserialize(file_get_contents($cache_path));
}
// If the cache or root path in it are invalid then regenerate
if (empty($cache) || empty($cache['less']['root']) || !file_exists($cache['less']['root'])) {
$cache = array('vars' => $vars, 'less' => DUDE_THEME_DIR . "/less/{$handle}.less");
}
// less config
$less->setFormatter("compressed");
$less->setVariables($vars);
$less_cache = $less->cachedCompile($cache['less'], false);
if (!file_exists($css_path) || empty($cache) || empty($cache['less']['updated']) || $less_cache['updated'] > $cache['less']['updated']) {
file_put_contents($cache_path, serialize(array('vars' => $vars, 'less' => $less_cache)));
file_put_contents($css_path, $less_cache['compiled']);
} elseif ($vars !== $cache['vars']) {
$less_cache = $less->cachedCompile($cache['less'], true);
file_put_contents($cache_path, serialize(array('vars' => $vars, 'less' => $less_cache)));
file_put_contents($css_path, $less_cache['compiled']);
}
} catch (exception $ex) {
qa_fatal_error($ex->getMessage());
}
// return the compiled stylesheet with the query string it had if any
$url = DUDE_THEME_URL . "/css/{$handle}.css";
echo '<link href="' . $url . '" type="text/css" rel="stylesheet">';
}
示例10: autoCompileLess
function autoCompileLess($inputFile, $outputFile)
{
// load the cache
$cacheFile = $inputFile . ".cache";
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $inputFile;
}
$less = new lessc();
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
file_put_contents($cacheFile, serialize($newCache));
file_put_contents($outputFile, $newCache['compiled']);
}
}
示例11: lessc
function sh_theme_color_scheme($color = '')
{
$dir = SH_TH_ROOT;
include_once $dir . '/includes/thirdparty/lessc.inc.php';
if (!$color) {
$color = _WSH()->option('custom_color_scheme');
}
if (!$color) {
return;
}
$less = new lessc();
$less->setVariables(array("color" => $color));
// create a new cache object, and compile
$cache = $less->cachedCompile(_WSH()->includes("/css/color.less"));
return $cache['compiled'];
file_put_contents(_WSH()->includes('/css/colors.css'), $cache["compiled"]);
}
示例12: loadcssfile
function loadcssfile($file, $cacheFile)
{
// load the cache
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $file;
}
$less = new lessc();
$less->setFormatter("compressed");
$less->setImportDir(array(__ROOT__ . DS . ".." . DS . "style" . DS . "less"));
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
@file_put_contents($cacheFile, serialize($newCache));
}
return $newCache['compiled'];
}
示例13: autoCompileLess
function autoCompileLess($inputFile, $outputFile)
{
// load the cache
if ($_SERVER['PHP_SELF'] != "sobic" && $_SERVER['PHP_SELF'] != "./sobic") {
$cacheFile = $inputFile . ".cache";
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $inputFile;
}
$less = new lessc();
$less->setFormatter("compressed");
$newCache = $less->cachedCompile($cache);
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
file_put_contents($cacheFile, serialize($newCache));
file_put_contents($outputFile, $newCache['compiled']);
}
}
}
示例14: boot
public function boot(Application $app)
{
// Validate this params.
$this->validate($app);
// Define default formatter if not already set.
$formatter = isset($app['less.formatter']) ? $app['less.formatter'] : self::FORMATTER_CLASSIC;
$sourcesDir = $app['less.source_dir'];
$cacheDir = $app['less.cache_dir'];
$targetDir = $app['less.target_dir'];
$cacheContents = array();
foreach ($sourcesDir as $sourceDir) {
$files = scandir($sourceDir);
foreach ($files as $file) {
// if less file
if (substr($file, -5) === '.less') {
$cache = $cacheDir . $this->before('.less', $file) . '.css.cache';
// if file cached
if (file_exists($cache)) {
array_push($cacheContents, ['dir' => $sourceDir, 'name' => $file, 'file' => unserialize(file_get_contents($cache))]);
} else {
array_push($cacheContents, ['dir' => $sourceDir, 'name' => $file, 'file' => $sourceDir . $file]);
}
}
}
}
$handle = new \lessc();
$handle->setFormatter($formatter);
foreach ($cacheContents as $cacheContent) {
$newCache = $handle->cachedCompile($cacheContent['file']);
if (!is_array($cacheContent['file']) || $newCache["updated"] > $cacheContent['file']["updated"]) {
$target = $targetDir . $this->before('.less', $cacheContent['name']) . '.css';
$cache = $cacheDir . $this->before('.less', $cacheContent['name']) . '.css.cache';
// Write cache file
file_put_contents($cache, serialize($newCache));
// Write CSS file
file_put_contents($target, $newCache['compiled']);
// Change CSS permisions
if (isset($app['less.target_mode'])) {
chmod($target, $app['less.target_mode']);
}
}
}
}
示例15: autoCompileLess
function autoCompileLess()
{
// include lessc.inc
require_once get_template_directory() . '/style/less/lessc.inc.php';
// input and output location
$inputFile = get_template_directory() . '/style/less/style.less';
$outputFile = get_template_directory() . '/style/css/style.css';
// load the cache
$cacheFile = $inputFile . ".cache";
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $inputFile;
}
$less = new lessc();
// create a new cache object, and compile
$newCache = $less->cachedCompile($cache);
// output a LESS file, and cache file only if it has been modified since last compile
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
file_put_contents($cacheFile, serialize($newCache));
file_put_contents($outputFile, $newCache['compiled']);
}
//Second iteration for home theme.
// input and output location
$inputFile = get_template_directory() . '/style/less/templates/page-home.less';
$outputFile = get_template_directory() . '/style/css/templates/page-home.css';
// load the cache
$cacheFile = $inputFile . ".cache";
if (file_exists($cacheFile)) {
$cache = unserialize(file_get_contents($cacheFile));
} else {
$cache = $inputFile;
}
$less = new lessc();
// create a new cache object, and compile
$newCache = $less->cachedCompile($cache);
// output a LESS file, and cache file only if it has been modified since last compile
if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
file_put_contents($cacheFile, serialize($newCache));
file_put_contents($outputFile, $newCache['compiled']);
}
}