7 require_once 'Minify/Source.php';
10 * Maintain a single last modification time for a group of Minify sources to
11 * allow use of far off Expires headers in Minify.
15 * $groupSources = array(
16 * 'js' => array('file1.js', 'file2.js')
17 * ,'css' => array('file1.css', 'file2.css', 'file3.css')
20 * // during HTML generation
21 * $jsBuild = new Minify_Build($groupSources['js']);
22 * $cssBuild = new Minify_Build($groupSources['css']);
24 * $script = "<script type='text/javascript' src='"
25 * . $jsBuild->uri('/min.php/js') . "'></script>";
26 * $link = "<link rel='stylesheet' type='text/css' href='"
27 * . $cssBuild->uri('/min.php/css') . "'>";
30 * Minify::serve('Groups', array(
31 * 'groups' => $groupSources
32 * ,'setExpires' => (time() + 86400 * 365)
37 * @author Stephen Clay <steve@mrclay.org>
42 * Last modification time of all files in the build
46 public $lastModified = 0;
49 * String to use as ampersand in uri(). Set this to '&' if
50 * you are not HTML-escaping URIs.
54 public static $ampersand = '&';
57 * Get a time-stamped URI
60 * echo $b->uri('/site.js');
61 * // outputs "/site.js?1678242"
63 * echo $b->uri('/scriptaculous.js?load=effects');
64 * // outputs "/scriptaculous.js?load=effects&1678242"
68 * @param boolean $forceAmpersand (default = false) Force the use of ampersand to
69 * append the timestamp to the URI.
72 public function uri($uri, $forceAmpersand = false) {
73 $sep = ($forceAmpersand || strpos($uri, '?') !== false)
76 return "{$uri}{$sep}{$this->lastModified}";
80 * Create a build object
82 * @param array $sources array of Minify_Source objects and/or file paths
86 public function __construct($sources)
89 foreach ((array)$sources as $source) {
90 if ($source instanceof Minify_Source) {
91 $max = max($max, $source->lastModified);
92 } elseif (is_string($source)) {
93 if (0 === strpos($source, '//')) {
94 $source = $_SERVER['DOCUMENT_ROOT'] . substr($source, 1);
96 if (is_file($source)) {
97 $max = max($max, filemtime($source));
101 $this->lastModified = $max;