/** * @covers getCache */ public function testGetCache() { $parser = new ILess_Parser(); $this->assertInstanceOf('ILess_CacheInterface', $parser->getCache()); $parser = new ILess_Parser(array(), new ILess_Cache_FileSystem(array('cache_dir' => sys_get_temp_dir()))); $this->assertInstanceOf('ILess_CacheInterface', $parser->getCache()); }
<?php require_once '_bootstrap.php'; // create the parser $parser = new ILess_Parser(array(), new ILess_Cache_FileSystem(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); $css = $parser->getCSS(); // what have been imported?