]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Minify/extlib/minify/min/lib/Minify/Controller/Files.php
83f028adf7479c09c2e1a93d6f2aacd45af3ba80
[quix0rs-gnu-social.git] / plugins / Minify / extlib / minify / min / lib / Minify / Controller / Files.php
1 <?php
2 /**
3  * Class Minify_Controller_Files  
4  * @package Minify
5  */
6
7 require_once 'Minify/Controller/Base.php';
8
9 /**
10  * Controller class for minifying a set of files
11  * 
12  * E.g. the following would serve the minified Javascript for a site
13  * <code>
14  * Minify::serve('Files', array(
15  *     'files' => array(
16  *         '//js/jquery.js'
17  *         ,'//js/plugins.js'
18  *         ,'/home/username/file.js'
19  *     )
20  * ));
21  * </code>
22  * 
23  * As a shortcut, the controller will replace "//" at the beginning
24  * of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
25  *
26  * @package Minify
27  * @author Stephen Clay <steve@mrclay.org>
28  */
29 class Minify_Controller_Files extends Minify_Controller_Base {
30     
31     /**
32      * Set up file sources
33      * 
34      * @param array $options controller and Minify options
35      * @return array Minify options
36      * 
37      * Controller options:
38      * 
39      * 'files': (required) array of complete file paths, or a single path
40      */
41     public function setupSources($options) {
42         // strip controller options
43         
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;
50         }
51         unset($options['files']);
52         
53         $sources = array();
54         foreach ($files as $file) {
55             if ($file instanceof Minify_Source) {
56                 $sources[] = $file;
57                 continue;
58             }
59             if (0 === strpos($file, '//')) {
60                 $file = $_SERVER['DOCUMENT_ROOT'] . substr($file, 1);
61             }
62             $realPath = realpath($file);
63             if (is_file($realPath)) {
64                 $sources[] = new Minify_Source(array(
65                     'filepath' => $realPath
66                 ));    
67             } else {
68                 $this->log("The path \"{$file}\" could not be found (or was not a file)");
69                 return $options;
70             }
71         }
72         if ($sources) {
73             $this->sources = $sources;
74         }
75         return $options;
76     }
77 }
78