8 * Maintain a single last modification time for a group of Minify sources to
9 * allow use of far off Expires headers in Minify.
13 * $groupSources = array(
14 * 'js' => array('file1.js', 'file2.js')
15 * ,'css' => array('file1.css', 'file2.css', 'file3.css')
18 * // during HTML generation
19 * $jsBuild = new Minify_Build($groupSources['js']);
20 * $cssBuild = new Minify_Build($groupSources['css']);
22 * $script = "<script type='text/javascript' src='"
23 * . $jsBuild->uri('/min.php/js') . "'></script>";
24 * $link = "<link rel='stylesheet' type='text/css' href='"
25 * . $cssBuild->uri('/min.php/css') . "'>";
28 * Minify::serve('Groups', array(
29 * 'groups' => $groupSources
30 * ,'setExpires' => (time() + 86400 * 365)
35 * @author Stephen Clay <steve@mrclay.org>
40 * Last modification time of all files in the build
44 public $lastModified = 0;
47 * String to use as ampersand in uri(). Set this to '&' if
48 * you are not HTML-escaping URIs.
52 public static $ampersand = '&';
55 * Get a time-stamped URI
58 * echo $b->uri('/site.js');
59 * // outputs "/site.js?1678242"
61 * echo $b->uri('/scriptaculous.js?load=effects');
62 * // outputs "/scriptaculous.js?load=effects&1678242"
66 * @param boolean $forceAmpersand (default = false) Force the use of ampersand to
67 * append the timestamp to the URI.
70 public function uri($uri, $forceAmpersand = false) {
71 $sep = ($forceAmpersand || strpos($uri, '?') !== false)
74 return "{$uri}{$sep}{$this->lastModified}";
78 * Create a build object
80 * @param array $sources array of Minify_Source objects and/or file paths
84 public function __construct($sources)
87 foreach ((array)$sources as $source) {
88 if ($source instanceof Minify_Source) {
89 $max = max($max, $source->lastModified);
90 } elseif (is_string($source)) {
91 if (0 === strpos($source, '//')) {
92 $source = $_SERVER['DOCUMENT_ROOT'] . substr($source, 1);
94 if (is_file($source)) {
95 $max = max($max, filemtime($source));
99 $this->lastModified = $max;