From 2894d8cac0eadb5385eb4f4af4a060cc75abd0a4 Mon Sep 17 00:00:00 2001 From: Chris Blumberg Date: Tue, 25 Sep 2012 12:19:07 -0400 Subject: [PATCH] Partial fix for #311, updated checkedCompile to allow for an array of files to be checked against the output file --- lessc.inc.php | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/lessc.inc.php b/lessc.inc.php index c42147c5..03a30ba2 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -1619,11 +1619,38 @@ public function compileFile($fname, $outFname = null) { return $out; } - // compile only if changed input has changed or output doesn't exist - public function checkedCompile($in, $out) { - if (!is_file($out) || filemtime($in) > filemtime($out)) { - $this->compileFile($in, $out); - return true; + /* + * Checks 1 or more files modified time to see if they are newer then the output file. + * If a file is newer then the output file, it compiles the file into the output file. + * + * @param mixed $in: 1 filename or an array of filenames to be checked against. + * @param string filename $out: the output file to compare the time against. + * @param string filename $fileToCompile: if passing an array, the file to compile if + * one of the files is newer then the output. + */ + public function checkedCompile($in, $out, $fileToCompile = NULL) { + if( is_array($in) ) + { + if( !isset( $fileToCompile )) + { + throw new Exception('The 3rd argument must be set as the file you want compiled if one fo the files is newer'); + } + + foreach( $in as $file ) + { + if(!is_file($out) || filemtime($file) > filemtime($out)) + { + $this->compileFile($fileToCompile, $out); + return true; + } + } + }else + { + if (!is_file($out) || filemtime($in) > filemtime($out)) + { + $this->compileFile($in, $out); + return true; + } } return false; }