Ejemplo n.º 1
0
 /**
  * @covers getCache
  */
 public function testGetCache()
 {
     $parser = new Parser();
     $this->assertInstanceOf('ILess\\Cache\\CacheInterface', $parser->getCache());
     $parser = new Parser([], new FileSystemCache(['cache_dir' => sys_get_temp_dir()]));
     $this->assertInstanceOf('ILess\\Cache\\CacheInterface', $parser->getCache());
 }
Ejemplo n.º 2
0
<?php

use ILess\Parser;
use ILess\Cache\FileSystemCache;
require_once '_bootstrap.php';
// create the parser
$parser = new Parser(array(), new FileSystemCache(array('cache_dir' => dirname(__FILE__) . '/cache')));
$file = dirname(__FILE__) . '/less/test.less';
// create your cache key
$cacheKey = md5($file);
$importer = $parser->getImporter();
$cache = $parser->getCache();
$rebuild = true;
$cssLastModified = -1;
if ($cache->has($cacheKey)) {
    $rebuild = false;
    list($css, $importedFiles) = $cache->get($cacheKey);
    // we need to check if the file has been modified
    foreach ($importedFiles as $importedFileArray) {
        list($lastModifiedBefore, $path, $currentFileInfo) = $importedFileArray;
        $lastModified = $importer->getLastModified($path, $currentFileInfo);
        $cssLastModified = max($lastModified, $cssLastModified);
        if ($lastModifiedBefore != $lastModified) {
            $rebuild = true;
            // no need to continue, we will rebuild the CSS
            break;
        }
    }
}
if ($rebuild) {
    $parser->parseFile($file);