3 * Class Minify_Controller_Files
7 require_once 'Minify/Controller/Base.php';
10 * Controller class for minifying a set of files
12 * E.g. the following would serve the minified Javascript for a site
14 * Minify::serve('Files', array(
18 * ,'/home/username/file.js'
23 * As a shortcut, the controller will replace "//" at the beginning
24 * of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
27 * @author Stephen Clay <steve@mrclay.org>
29 class Minify_Controller_Files extends Minify_Controller_Base {
34 * @param array $options controller and Minify options
35 * @return array Minify options
39 * 'files': (required) array of complete file paths, or a single path
41 public function setupSources($options) {
42 // strip controller options
44 $files = $options['files'];
45 // if $files is a single object, casting will break it
46 if (is_object($files)) {
47 $files = array($files);
48 } elseif (! is_array($files)) {
49 $files = (array)$files;
51 unset($options['files']);
54 foreach ($files as $file) {
55 if ($file instanceof Minify_Source) {
59 if (0 === strpos($file, '//')) {
60 $file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
62 $realPath = realpath($file);
63 if (is_file($realPath)) {
64 $sources[] = new Minify_Source(array(
65 'filepath' => $realPath
68 $this->log("The path \"{$file}\" could not be found (or was not a file)");
73 $this->sources = $sources;