/**
* Get content of file, parse it with lessc and return formatted css
*
* @todo allow for css-file name only, and search it in all avail. webroots
* @param string $file full path to file
* @param array $options Additional options to control flow of method
* - header - controls, whether to prepend a header
* - cache - controls, whether to cache the result
* - cachePath - Where to cache files, defaults to
* resources/tmp/cache
* @return string|boolean generated css, false in case of error
*/
public static function file($file, array $options = array())
{
$defaults = array('header' => true, 'cache' => true, 'cachePath' => Libraries::get(true, 'resources') . '/tmp/cache', 'cacheKey' => Inflector::slug(str_replace(array(LITHIUM_APP_PATH, '.less'), array('', '.css'), $file)));
$options += $defaults;
$css_file = $options['cachePath'] . '/' . $options['cacheKey'];
if (file_exists($css_file) && filemtime($css_file) >= filemtime($file)) {
return file_get_contents($css_file);
}
if (!file_exists($file)) {
return false;
}
try {
$less = static::_getLess($file);
$output = $less->parse();
} catch (Exception $e) {
$output = "/* less compiler exception: {$e->getMessage()} */";
}
if ($options['header']) {
$output = static::_prependHeader($output);
}
if ($options['cache']) {
file_put_contents($css_file, $output);
}
return $output;
}