本文整理汇总了PHP中Less_Cache类的典型用法代码示例。如果您正苦于以下问题:PHP Less_Cache类的具体用法?PHP Less_Cache怎么用?PHP Less_Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Less_Cache类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: doActionCleanAggregationCache
/**
* Clean aggregation cache directory
*
* @return void
*/
public function doActionCleanAggregationCache()
{
\Includes\Utils\FileManager::unlinkRecursive(LC_DIR_CACHE_RESOURCES);
\Less_Cache::SetCacheDir(LC_DIR_DATACACHE);
\Less_Cache::CleanCache();
\XLite\Core\TopMessage::addInfo('Aggregation cache has been cleaned');
}
开发者ID:kirkbauer2,项目名称:kirkxc,代码行数:12,代码来源:CssJsPerformance.php
示例2: 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 . '">';
}
开发者ID:salatproduction,项目名称:Unona-Landing-Standalone,代码行数:7,代码来源:init.php
示例3: getLessCss
/**
* getLessCss
*
* Returns compiled css from less file
* @version 1.0.0
*/
public function getLessCss($options = array('files' => array(), 'variables' => array()))
{
// extract array params
extract($options);
// If files are not passed retutn null
if (!isset($files)) {
return null;
}
// If variables are not passed set empty
if (!isset($variables)) {
$variables = array();
}
//get basepath helper
$basePath = $this->serviceLocator->get('ViewHelperManager')->get('basePath');
// less file array
$files_arr = array();
foreach ($files as $file) {
$files_arr[INFINITY_PUBLIC_PATH . $file] = $basePath($file);
}
// less compile options
$less_options = array('cache_dir' => INFINITY_PUBLIC_CACHE_PATH, 'compress' => true);
// Generate css file from less file, if css already cached then return that one
$css_file_name = \Less_Cache::Get($files_arr, $less_options, $variables);
// Returns compiled css file url
return $basePath('/cache/' . $css_file_name);
}
开发者ID:vijaypatelwork,项目名称:infinity,代码行数:32,代码来源:LessService.php
示例4: getCompiledFile
/**
* @param string $file
* @return bool|string
* @throws \Exception
*/
public static function getCompiledFile($file)
{
$file = GeneralUtility::getFileAbsFileName($file);
$pathParts = pathinfo($file);
if ($pathParts['extension'] === 'less') {
try {
$options = array('cache_dir' => GeneralUtility::getFileAbsFileName('typo3temp/mooxcore'));
$settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_mooxcore.']['settings.'] ?: array();
if ($settings['cssSourceMapping']) {
// enable source mapping
$optionsForSourceMap = array('sourceMap' => true, 'sourceMapWriteTo' => GeneralUtility::getFileAbsFileName('typo3temp/mooxcore') . '/mooxcore.map', 'sourceMapURL' => '/typo3temp/mooxcore/mooxcore.map', 'sourceMapBasepath' => PATH_site, 'sourceMapRootpath' => '/');
$options += $optionsForSourceMap;
// disable CSS compression
/** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
$pageRenderer->disableCompressCss();
}
if ($settings['overrideLessVariables']) {
$variables = self::getVariablesFromConstants();
} else {
$variables = array();
}
$files = array();
$files[$file] = '../../' . str_replace(PATH_site, '', dirname($file)) . '/';
$compiledFile = \Less_Cache::Get($files, $options, $variables);
$file = "typo3temp/mooxcore/" . $compiledFile;
return $file;
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}
return false;
}
开发者ID:dcngmbh,项目名称:moox_core,代码行数:38,代码来源:CompileService.php
示例5: CompareFile
/**
* Compare the parser results with the expected css
*
*/
function CompareFile($expected_file)
{
$less_file = $this->TranslateFile($expected_file);
$expected_css = trim(file_get_contents($expected_file));
// Check with standard parser
echo "\n " . basename($expected_file);
echo "\n - Standard Compiler";
$parser = new Less_Parser();
$parser->parseFile($less_file);
$css = $parser->getCss();
$css = trim($css);
$this->assertEquals($expected_css, $css);
// Check with cache
if ($this->cache_dir) {
$options = array('cache_dir' => $this->cache_dir);
$files = array($less_file => '');
echo "\n - Regenerating Cache";
$css_file_name = Less_Cache::Regen($files, $options);
$css = file_get_contents($this->cache_dir . '/' . $css_file_name);
$css = trim($css);
$this->assertEquals($expected_css, $css);
// Check using the cached data
echo "\n - Using Cache";
$css_file_name = Less_Cache::Get($files, $options);
$css = file_get_contents($this->cache_dir . '/' . $css_file_name);
$css = trim($css);
$this->assertEquals($expected_css, $css);
}
}
开发者ID:Flesh192,项目名称:magento,代码行数:33,代码来源:FixturesTest.php
示例6: handle_lesscss_request
function handle_lesscss_request($lessfile, $relative_path)
{
$dir = forceslash(sys_get_temp_dir());
$css_file = Less_Cache::Get([$lessfile => $relative_path], ['sourceMap' => true, 'compress' => true, 'relativeUrls' => true, 'cache_dir' => $dir]);
$css = file_get_contents($dir . $css_file);
header('Content-Type: text/css');
header('Content-Length: ' . strlen($css));
print $css;
}
开发者ID:agnat,项目名称:streaming-website,代码行数:9,代码来源:helper.php
示例7: css
function css($file, $media = null)
{
/* Only initiate if webiste is in dev mode or a ?flush is called */
if (preg_match('/\\.less$/i', $file) || Director::isDev() || isset($_GET['flush'])) {
/* If file is CSS, check if there is a LESS file */
if (preg_match('/\\.css$/i', $file)) {
$less = preg_replace('/\\.css$/i', '.less', $file);
if (is_file(Director::getAbsFile($less))) {
$file = $less;
}
}
/* If less file exists, then check/compile it */
if (preg_match('/\\.less$/i', $file)) {
$out = preg_replace('/\\.less$/i', '.css', $file);
$css_file = Director::getAbsFile($out);
$options = array();
/* Automatically compress if in live mode */
if (Director::isLive()) {
$options['compress'] = true;
}
try {
/* Force recompile & only write to css if updated */
if (isset($_GET['flush']) || !Director::isLive()) {
/* Force deleting of all cache files on flush */
if (file_exists(self::$cacheDir) && isset($_GET['flush']) && !self::$already_flushed) {
$paths = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(self::$cacheDir, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($paths as $path) {
$path->isDir() && !$path->isLink() ? rmdir($path->getPathname()) : unlink($path->getPathname());
}
/* make sure we only flush once per request and not for each *.less */
self::$already_flushed = true;
}
/* Set cache directory */
$options['cache_dir'] = self::$cacheDir;
/* Set cache method */
$options['cache_method'] = self::$cacheMethod;
/* Calculate the LESS file's parent URL */
$css_dir = dirname(Director::baseURL() . $file) . '/';
/* Generate and return cached file path */
$cached_file = self::$cacheDir . '/' . Less_Cache::Get(array(Director::getAbsFile($file) => $css_dir), $options, self::$variables);
/* check cache vs. css and overwrite if necessary */
if (!is_file($css_file) || md5_file($css_file) != md5_file($cached_file)) {
copy($cached_file, $css_file);
}
}
} catch (Exception $ex) {
trigger_error('Less.php fatal error: ' . $ex->getMessage(), E_USER_ERROR);
}
$file = $out;
}
}
/* Return css file path */
return parent::css($file, $media);
}
开发者ID:helpfulrobot,项目名称:axllent-silverstripe-less,代码行数:54,代码来源:LessCompiler.php
示例8: compile
/**
* @return array
* @throws Exception
*/
public function compile()
{
$lessFiles = $this->getFileList($this->config->fileNames);
try {
$filePath = \Less_Cache::Get($lessFiles, $this->setOptions());
$error = false;
} catch (\Exception $e) {
$filePath = false;
$error = $e->getMessage();
}
$arReturn = array('filePath' => $filePath, 'error' => $error);
return $arReturn;
}
开发者ID:xamedow,项目名称:bqs-site,代码行数:17,代码来源:lessCompiler.php
示例9: __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 . "' />";
}
开发者ID:remithomas,项目名称:rt-less,代码行数:19,代码来源:LessCss.php
示例10: _compileFile
/**
* @param $inputFilename
* @param $outputFilename
* @param $cacheFilename
*
* @return string
*/
protected function _compileFile($inputFilename, $preparedFilename, $outputFilename, $cacheFilename)
{
try {
$options = array('import_dirs' => array(dirname($inputFilename) => dirname($inputFilename), PATH_site => PATH_site), 'cache_dir' => GeneralUtility::getFileAbsFileName('typo3temp/DynCss/Cache'));
if ($this->config['enableDebugMode']) {
$options['sourceMap'] = TRUE;
}
$files = array($inputFilename => '');
$compiledFile = $options['cache_dir'] . '/' . \Less_Cache::Get($files, $options, $this->overrides);
return file_get_contents($compiledFile);
} catch (\Exception $e) {
return $e;
}
}
开发者ID:blumenbach,项目名称:bb-online.neu,代码行数:21,代码来源:LessParser.php
示例11: CompileFile
/**
* Компилирует файл less и возвращает текст css-файла
*
* @param $aFile
* @param $sCacheDir
* @param $sMapPath
* @param $aParams
* @param $bCompress
* @return string
*/
public function CompileFile($aFile, $sCacheDir, $sMapPath, $aParams, $bCompress)
{
if (!($sMapPath && $sCacheDir && $aFile)) {
return '';
}
try {
$options = array('sourceMap' => TRUE, 'sourceMapWriteTo' => $sMapPath, 'sourceMapURL' => E::ModuleViewerAsset()->AssetFileUrl($sMapPath), 'cache_dir' => $sCacheDir);
if ($bCompress) {
$options = array_merge($options, array('compress' => TRUE));
}
$sCssFileName = Less_Cache::Get($aFile, $options, $aParams);
return file_get_contents($sCacheDir . $sCssFileName);
} catch (Exception $e) {
E::ModuleMessage()->AddErrorSingle($e->getMessage());
}
return '';
}
开发者ID:AntiqS,项目名称:altocms,代码行数:27,代码来源:Less.class.php
示例12: smarty_function_lessphp
function smarty_function_lessphp($params, &$smarty)
{
if (!isset($params['file']) or !($file = $params['file'])) {
return;
}
$modx = $smarty->modx;
$template_dir = MODX_ASSETS_PATH . 'components/modxsite/templates/';
$template = $modx->getOption('modxSmarty.template', $scriptProperties, 'default');
$template_url = $modx->getOption('modxSite.template_url');
if ($pre_template = $modx->getOption('modxSmarty.pre_template', null, false)) {
$template = $pre_template;
}
$template_url .= $template . '/';
$template_dir .= $template . '/';
$less_fname = $template_dir . $file;
$less_files = array($less_fname => $template_url . 'css/');
$options = array('cache_dir' => $template_dir . 'cache/', 'compress' => true);
return $template_url . 'cache/' . Less_Cache::Get($less_files, $options);
}
开发者ID:Tramp1357,项目名称:wood,代码行数:19,代码来源:function.lessphp.php
示例13: onBeforeInit
/**
* Perform the crunch work of compiling less files on initilisation,
* but only do this when we are running on dev (and the file is in
* need of updating).
*
*/
public function onBeforeInit()
{
// Only check and compile when on dev
if (Director::isDev()) {
$files = LessCompilerConfig::config()->file_mappings;
$root_path = LessCompilerConfig::config()->root_path;
$temp_folder = TEMP_FOLDER;
if (is_array($files)) {
$theme_dir = Controller::join_links("themes", SSViewer::current_theme());
$base_theme = Controller::join_links($theme_dir, SSViewer::current_theme());
$options = array('cache_dir' => $temp_folder);
if (LessCompilerConfig::config()->compress) {
$options['compress'] = true;
}
// First loop through all files and deal with inputs
foreach ($files as $input => $output) {
if ($input && $output) {
// Does output and input contain a path
if (strpos($input, '/') === false) {
$input = Controller::join_links($theme_dir, "less", $input);
}
if (strpos($output, '/') === false) {
$output = Controller::join_links($theme_dir, "css", $output);
}
// Now append the full system path to the input
// and output file.
$input = Controller::join_links(BASE_PATH, $input);
$output = Controller::join_links(BASE_PATH, $output);
// Finally try to compile our less files
try {
$css_file_name = Less_Cache::Get(array($input => $root_path), $options);
$css = file_get_contents(Controller::join_links($temp_folder, $css_file_name));
$output_file = fopen($output, "w");
fwrite($output_file, $css);
fclose($output_file);
} catch (exception $e) {
error_log($e->getMessage());
}
}
}
}
}
}
开发者ID:i-lateral,项目名称:silverstripe-lesscompiler,代码行数:49,代码来源:LessCompilerControllerExtension.php
示例14: 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' );
}
}
}
}
开发者ID:nicomollet,项目名称:stormbringer,代码行数:43,代码来源:styles.php
示例15: filterLoad
public function filterLoad(AssetInterface $asset)
{
$filePath = $asset->getSourceRoot() . DS . $asset->getSourcePath();
Tlog::getInstance()->addDebug("Starting CSS processing: {$filePath}...");
$importDirs = [];
if ($dir = $asset->getSourceDirectory()) {
$importDirs[$dir] = '';
}
foreach ($this->loadPaths as $loadPath) {
$importDirs[$loadPath] = '';
}
$options = ['cache_dir' => $this->cacheDir, 'relativeUrls' => false, 'compress' => true, 'import_dirs' => $importDirs];
$css_file_name = \Less_Cache::Get([$filePath => ''], $options);
$content = @file_get_contents($this->cacheDir . DS . $css_file_name);
if ($content === false) {
$content = '';
Tlog::getInstance()->warning("Compilation of {$filePath} did not generate an output file.");
}
$asset->setContent($content);
Tlog::getInstance()->addDebug("CSS processing done.");
}
开发者ID:margery,项目名称:thelia,代码行数:21,代码来源:LessDotPhpFilter.php
示例16: index
public function index()
{
$filename = implode('/', array_slice($this->uri->rsegments, 2));
$filename = preg_replace('/\\.{2,}/', '', $filename);
// Sanitazing the name.
$base_path = DEFAULTFCPATH;
if (defined('APPSEGMENT') && APPSEGMENT != '') {
$base_path .= APPSEGMENT . '/';
}
$file_path = $base_path . $filename;
$this->config->load('less_compile', false, true);
$less_compile_config = !empty($this->config->config['less_compile']) && is_array($this->config->config['less_compile']) ? $this->config->config['less_compile'] : array();
if (empty($less_compile_config)) {
$this->_show_404();
return;
}
$found = false;
foreach ($less_compile_config as $options) {
$name = isset($options['name']) ? (string) $options['name'] : '';
$source = isset($options['source']) ? (string) $options['source'] : '';
$destination = isset($options['destination']) ? (string) $options['destination'] : '';
if ($destination == $file_path && $name != '' && $source != '' && $destination != '') {
$found = true;
break;
}
}
if (!$found) {
$this->_show_404();
return;
}
unset($options['name']);
unset($options['source']);
unset($options['destination']);
$cache_dir = WRITABLEPATH . 'cache_lessphp/' . sha1($name) . '/';
is_dir($cache_dir) or @mkdir($cache_dir, 0755, TRUE);
$options['cache_dir'] = $cache_dir;
$options['cache_method'] = 'serialize';
$this->output->set_content_type('text/css');
$this->output->set_output(@(string) file_get_contents($cache_dir . Less_Cache::Get(array($source => ''), $options)));
}
开发者ID:ezequielrosa,项目名称:starter-public-edition-4,代码行数:40,代码来源:Css_server_controller.php
示例17: getCompiledFile
/**
* @param string $file
* @return bool|string
*/
public static function getCompiledFile($file)
{
$file = GeneralUtility::getFileAbsFileName($file);
$pathParts = pathinfo($file);
if ($pathParts['extension'] === 'less') {
if (!class_exists('Less_Cache')) {
$autoload = GeneralUtility::makeInstance('Less_Autoloader');
$autoload::register();
}
try {
$options = array('cache_dir' => GeneralUtility::getFileAbsFileName('typo3temp/mooxcore'));
$variables = self::getVariablesFromConstants();
$files = array();
$files[$file] = "";
$compiledFile = \Less_Cache::Get($files, $options, $variables);
$file = "typo3temp/mooxcore/" . $compiledFile;
return $file;
} catch (\Exception $e) {
$error_message = $e->getMessage();
}
}
return false;
}
开发者ID:preinboth,项目名称:moox_core,代码行数:27,代码来源:CompileService.php
示例18: CheckCacheDir
public static function CheckCacheDir()
{
Less_Cache::$cache_dir = str_replace('\\', '/', Less_Cache::$cache_dir);
Less_Cache::$cache_dir = rtrim(Less_Cache::$cache_dir, '/') . '/';
if (!file_exists(Less_Cache::$cache_dir)) {
if (!mkdir(Less_Cache::$cache_dir)) {
throw new Less_Exception_Parser('Less.php cache directory couldn\'t be created: ' . Less_Cache::$cache_dir);
}
} elseif (!is_dir(Less_Cache::$cache_dir)) {
throw new Less_Exception_Parser('Less.php cache directory doesn\'t exist: ' . Less_Cache::$cache_dir);
} elseif (!is_writable(Less_Cache::$cache_dir)) {
throw new Less_Exception_Parser('Less.php cache directory isn\'t writable: ' . Less_Cache::$cache_dir);
}
}
开发者ID:grlf,项目名称:eyedock,代码行数:14,代码来源:cache.php
示例19: GetRules
/**
* Return the results of parsePrimary for $file_path
* Use cache and save cached results if possible
*
* @param string|null $file_path
*/
private function GetRules($file_path)
{
$this->SetInput($file_path);
$cache_file = $this->CacheFile($file_path);
if ($cache_file) {
if (Less_Parser::$options['cache_method'] == 'callback') {
if (is_callable(Less_Parser::$options['cache_callback_get'])) {
$cache = call_user_func_array(Less_Parser::$options['cache_callback_get'], array($this, $file_path, $cache_file));
if ($cache) {
$this->UnsetInput();
return $cache;
}
}
} elseif (file_exists($cache_file)) {
switch (Less_Parser::$options['cache_method']) {
// Using serialize
// Faster but uses more memory
case 'serialize':
$cache = unserialize(file_get_contents($cache_file));
if ($cache) {
touch($cache_file);
$this->UnsetInput();
return $cache;
}
break;
// Using generated php code
// Using generated php code
case 'var_export':
case 'php':
$this->UnsetInput();
return include $cache_file;
}
}
}
$rules = $this->parsePrimary();
if ($this->pos < $this->input_len) {
throw new Less_Exception_Chunk($this->input, null, $this->furthest, $this->env->currentFileInfo);
}
$this->UnsetInput();
//save the cache
if ($cache_file) {
if (Less_Parser::$options['cache_method'] == 'callback') {
if (is_callable(Less_Parser::$options['cache_callback_set'])) {
call_user_func_array(Less_Parser::$options['cache_callback_set'], array($this, $file_path, $cache_file, $rules));
}
} else {
//msg('write cache file');
switch (Less_Parser::$options['cache_method']) {
case 'serialize':
file_put_contents($cache_file, serialize($rules));
break;
case 'php':
file_put_contents($cache_file, '<?php return ' . self::ArgString($rules) . '; ?>');
break;
case 'var_export':
//Requires __set_state()
file_put_contents($cache_file, '<?php return ' . var_export($rules, true) . '; ?>');
break;
}
Less_Cache::CleanCache();
}
}
return $rules;
}
开发者ID:netAction,项目名称:diabetes-schule-berlin-wordpress,代码行数:70,代码来源:Less.php
示例20: SetCacheDir
public static function SetCacheDir($dir)
{
Less_Cache::$cache_dir = $dir;
}
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:4,代码来源:Cache.php
注:本文中的Less_Cache类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论