summaryrefslogtreecommitdiffstats
path: root/admin/survey/minify/lib/Minify/Controller/Groups.php
blob: 521a58eb50043dabadce62ad5d7e5f95e4bc19a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
 * Class Minify_Controller_Groups
 * @package Minify
 */

/**
 * Controller class for serving predetermined groups of minimized sets, selected
 * by PATH_INFO
 *
 * <code>
 * Minify::serve('Groups', array(
 *     'groups' => array(
 *         'css' => array('//css/type.css', '//css/layout.css')
 *        ,'js' => array('//js/jquery.js', '//js/site.js')
 *     )
 * ));
 * </code>
 *
 * If the above code were placed in /serve.php, it would enable the URLs
 * /serve.php/js and /serve.php/css
 *
 * @package Minify
 * @author Stephen Clay <steve@mrclay.org>
 */
class Minify_Controller_Groups extends Minify_Controller_Files
{

    /**
     * Set up groups of files as sources
     *
     * @param array $options controller and Minify options
     *
     * 'groups': (required) array mapping PATH_INFO strings to arrays
     * of complete file paths. @see Minify_Controller_Groups
     *
     * @return array Minify options
     */
    public function createConfiguration(array $options)
    {
        // strip controller options
        $groups = $options['groups'];
        unset($options['groups']);

        $server = $this->env->server();

        // mod_fcgid places PATH_INFO in ORIG_PATH_INFO
        if (isset($server['ORIG_PATH_INFO'])) {
            $pathInfo = substr($server['ORIG_PATH_INFO'], 1);
        } elseif (isset($server['PATH_INFO'])) {
            $pathInfo = substr($server['PATH_INFO'], 1);
        } else {
            $pathInfo = false;
        }

        if (false === $pathInfo || ! isset($groups[$pathInfo])) {
            // no PATH_INFO or not a valid group
            $this->logger->info("Missing PATH_INFO or no group set for \"$pathInfo\"");

            return new Minify_ServeConfiguration($options);
        }

        $files = $groups[$pathInfo];
        // if $files is a single object, casting will break it
        if (is_object($files)) {
            $files = array($files);
        } elseif (! is_array($files)) {
            $files = (array)$files;
        }

        $options['files'] = $files;

        return parent::createConfiguration($options);
    }
}