]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Minify/extlib/minify/min/lib/Minify/Controller/Groups.php
Added minify plugin
[quix0rs-gnu-social.git] / plugins / Minify / extlib / minify / min / lib / Minify / Controller / Groups.php
1 <?php
2 /**
3  * Class Minify_Controller_Groups  
4  * @package Minify
5  */
6
7 require_once 'Minify/Controller/Base.php';
8
9 /**
10  * Controller class for serving predetermined groups of minimized sets, selected
11  * by PATH_INFO
12  * 
13  * <code>
14  * Minify::serve('Groups', array( 
15  *     'groups' => array(
16  *         'css' => array('//css/type.css', '//css/layout.css')
17  *        ,'js' => array('//js/jquery.js', '//js/site.js')
18  *     )
19  * ));
20  * </code>
21  * 
22  * If the above code were placed in /serve.php, it would enable the URLs
23  * /serve.php/js and /serve.php/css
24  * 
25  * As a shortcut, the controller will replace "//" at the beginning
26  * of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
27  * 
28  * @package Minify
29  * @author Stephen Clay <steve@mrclay.org>
30  */
31 class Minify_Controller_Groups extends Minify_Controller_Base {
32     
33     /**
34      * Set up groups of files as sources
35      * 
36      * @param array $options controller and Minify options
37      * @return array Minify options
38      * 
39      * Controller options:
40      * 
41      * 'groups': (required) array mapping PATH_INFO strings to arrays
42      * of complete file paths. @see Minify_Controller_Groups 
43      */
44     public function setupSources($options) {
45         // strip controller options
46         $groups = $options['groups'];
47         unset($options['groups']);
48         
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) 
54                 : false
55             );
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\"");
59             return $options;
60         }
61         $sources = array();
62         
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;
69         }
70         foreach ($files as $file) {
71             if ($file instanceof Minify_Source) {
72                 $sources[] = $file;
73                 continue;
74             }
75             if (0 === strpos($file, '//')) {
76                 $file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
77             }
78             $realPath = realpath($file);
79             if (is_file($realPath)) {
80                 $sources[] = new Minify_Source(array(
81                     'filepath' => $realPath
82                 ));    
83             } else {
84                 $this->log("The path \"{$file}\" could not be found (or was not a file)");
85                 return $options;
86             }
87         }
88         if ($sources) {
89             $this->sources = $sources;
90         }
91         return $options;
92     }
93 }
94