3 * Class Minify_Controller_Groups
7 require_once 'Minify/Controller/Base.php';
10 * Controller class for serving predetermined groups of minimized sets, selected
14 * Minify::serve('Groups', array(
16 * 'css' => array('//css/type.css', '//css/layout.css')
17 * ,'js' => array('//js/jquery.js', '//js/site.js')
22 * If the above code were placed in /serve.php, it would enable the URLs
23 * /serve.php/js and /serve.php/css
25 * As a shortcut, the controller will replace "//" at the beginning
26 * of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
29 * @author Stephen Clay <steve@mrclay.org>
31 class Minify_Controller_Groups extends Minify_Controller_Base {
34 * Set up groups of files as sources
36 * @param array $options controller and Minify options
37 * @return array Minify options
41 * 'groups': (required) array mapping PATH_INFO strings to arrays
42 * of complete file paths. @see Minify_Controller_Groups
44 public function setupSources($options) {
45 // strip controller options
46 $groups = $options['groups'];
47 unset($options['groups']);
49 // mod_fcgid places PATH_INFO in ORIG_PATH_INFO
50 $pi = isset($_SERVER['ORIG_PATH_INFO'])
51 ? substr($_SERVER['ORIG_PATH_INFO'], 1)
52 : (isset($_SERVER['PATH_INFO'])
53 ? substr($_SERVER['PATH_INFO'], 1)
56 if (false === $pi || ! isset($groups[$pi])) {
57 // no PATH_INFO or not a valid group
58 $this->log("Missing PATH_INFO or no group set for \"$pi\"");
63 $files = $groups[$pi];
64 // if $files is a single object, casting will break it
65 if (is_object($files)) {
66 $files = array($files);
67 } elseif (! is_array($files)) {
68 $files = (array)$files;
70 foreach ($files as $file) {
71 if ($file instanceof Minify_Source) {
75 if (0 === strpos($file, '//')) {
76 $file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
78 $realPath = realpath($file);
79 if (is_file($realPath)) {
80 $sources[] = new Minify_Source(array(
81 'filepath' => $realPath
84 $this->log("The path \"{$file}\" could not be found (or was not a file)");
89 $this->sources = $sources;