compiling multiple files in row fails to execute @import
i am trying to compile multiple files with the following code. Sadly the import statement within the files does not work after the first file is compiled and the compilation fails with exception about missing variables which are defined within the import
$lessc = new \lessc();
$dir = new \DirectoryIterator(LESS_SRC_DIR);
foreach ($dir as $fileInfo) {
// skip . && ..
if ($fileInfo->isDot()) {
continue;
}
// skip non less files
if ($fileInfo->getExtension() != 'less') {
continue;
}
$name = $fileInfo->getFilename();
// skip private less files
if (substr($name, 0, 1) == '_') {
continue;
}
$in = $fileInfo->getRealPath();
$out = LESS_TARGET_DIR . str_replace('less', 'css', $fileInfo->getFilename());
echo sprintf("%s %s %s\n", time(), $in, $out);
// $lessc->checkedCompile($in, $out);
$lessc->compileFile($in, $out);
}
when i compile one file at a time it works .. i guess something does not get reset or does get reset when it should not : D
the second i hit the submit button i had an idea which fixed my issue, maybe i was using it wrong? creating a new lessc instance within the loop helped. Feature or bug? working code:
$dir = new \DirectoryIterator(LESS_SRC_DIR);
foreach ($dir as $fileInfo) {
$lessc = new \lessc();
// skip . && ..
if ($fileInfo->isDot()) {
continue;
}
// skip non less files
if ($fileInfo->getExtension() != 'less') {
continue;
}
$name = $fileInfo->getFilename();
// skip private less files
if (substr($name, 0, 1) == '_') {
continue;
}
$in = $fileInfo->getRealPath();
$out = LESS_TARGET_DIR . str_replace('less', 'css', $fileInfo->getFilename());
echo sprintf("%s %s %s\n", time(), $in, $out);
// $lessc->checkedCompile($in, $out);
$lessc->compileFile($in, $out);
}
I can still reproduce the issue (as of v0.5.0). The error is thrown from the get method (protected function get($name)). There is something wrong with $this->env, I think that $this->env->imports gets reset so we loose the variables.
creating a new lessc instance within the loop helped. Feature or bug?
This indeed works, however I would consider this a bug since re-instantiating a class in a loop sounds more of a performance hit compared to a single initialization. Alas, I would like to see this issue fixed.
lessphp is amazing and it deserves the fix