public function compile($env, $args = array())
 {
     $frame = new \Less\Node\Ruleset(null, array());
     foreach ($this->params as $i => $param) {
         if (isset($param['name']) && $param['name']) {
             if ($val = isset($args[$i]) ? $args[$i] : $param['value']) {
                 $rule = new \Less\Node\Rule($param['name'], $val->compile($env));
                 array_unshift($frame->rules, $rule);
             } else {
                 throw new \Less\Exception\CompilerException("wrong number of arguments for " . $this->name . ' (' . count($args) . ' for ' . $this->arity . ')');
             }
         }
     }
     $_arguments = array();
     for ($i = 0; $i < max(count($this->params), count($args)); $i++) {
         $_arguments[] = isset($args[$i]) ? $args[$i] : $this->params[$i]['value'];
     }
     $ex = new \Less\Node\Expression($_arguments);
     array_unshift($frame->rules, new \Less\Node\Rule('@arguments', $ex->compile($env)));
     // duplicate the environment, adding new frames.
     $ruleSetEnv = new \Less\Environment();
     $ruleSetEnv->addFrame($this);
     $ruleSetEnv->addFrame($frame);
     $ruleSetEnv->addFrames($this->frames);
     $ruleSetEnv->addFrames($env->frames);
     $ruleset = new \Less\Node\Ruleset(null, $this->rules);
     return $ruleset->compile($ruleSetEnv);
 }
Beispiel #2
0
<?php

// Path to the less.php library files
$lessLibraryPath = __DIR__ . '/../lib/';
// Path to the css cache directory
$cachePath = __DIR__ . '/cache/';
// Register an autoload function
spl_autoload_register(function ($className) use($lessLibraryPath) {
    $fileName = $lessLibraryPath . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
    if (file_exists($fileName)) {
        require_once $fileName;
    }
});
// Create our environment
$env = new \Less\Environment();
$env->setCompress(true);
// Grab a comma separated list of files to parse from the query string.
$files = explode(',', isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '');
// Only allow inclusion of .less files in this directory
foreach ($files as $key => $file) {
    $files[$key] = pathinfo($file, PATHINFO_BASENAME);
    if (!file_exists($files[$key])) {
        unset($files[$key]);
    }
    if (pathinfo($file, PATHINFO_EXTENSION) != 'less') {
        unset($files[$key]);
    }
}
if (count($files)) {
    // Check for a cached version of the query string hash
    $hash = md5(array_reduce($files, function ($a, $b) {