本文整理汇总了PHP中Less_Cache类的典型用法代码示例。如果您正苦于以下问题:PHP Less_Cache类的具体用法?PHP Less_Cache怎么用?PHP Less_Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Less_Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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');
}
示例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 . '">';
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
示例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 . "' />";
}
示例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;
}
}
示例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 '';
}
示例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);
}
示例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());
}
}
}
}
}
}
示例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' );
}
}
}
}
示例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.");
}