3 * Class Minify_Controller_Groups
8 * Controller class for serving predetermined groups of minimized sets, selected
12 * Minify::serve('Groups', array(
14 * 'css' => array('//css/type.css', '//css/layout.css')
15 * ,'js' => array('//js/jquery.js', '//js/site.js')
20 * If the above code were placed in /serve.php, it would enable the URLs
21 * /serve.php/js and /serve.php/css
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_Groups extends Minify_Controller_Base {
32 * Set up groups of files as sources
34 * @param array $options controller and Minify options
36 * 'groups': (required) array mapping PATH_INFO strings to arrays
37 * of complete file paths. @see Minify_Controller_Groups
39 * @return array Minify options
41 public function setupSources($options) {
42 // strip controller options
43 $groups = $options['groups'];
44 unset($options['groups']);
46 // mod_fcgid places PATH_INFO in ORIG_PATH_INFO
47 $pi = isset($_SERVER['ORIG_PATH_INFO'])
48 ? substr($_SERVER['ORIG_PATH_INFO'], 1)
49 : (isset($_SERVER['PATH_INFO'])
50 ? substr($_SERVER['PATH_INFO'], 1)
53 if (false === $pi || ! isset($groups[$pi])) {
54 // no PATH_INFO or not a valid group
55 $this->log("Missing PATH_INFO or no group set for \"$pi\"");
60 $files = $groups[$pi];
61 // if $files is a single object, casting will break it
62 if (is_object($files)) {
63 $files = array($files);
64 } elseif (! is_array($files)) {
65 $files = (array)$files;
67 foreach ($files as $file) {
68 if ($file instanceof Minify_Source) {
72 if (0 === strpos($file, '//')) {
73 $file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
75 $realPath = realpath($file);
76 if (is_file($realPath)) {
77 $sources[] = new Minify_Source(array(
78 'filepath' => $realPath
81 $this->log("The path \"{$file}\" could not be found (or was not a file)");
86 $this->sources = $sources;