mirror of
https://github.com/mrclay/minify.git
synced 2025-02-22 07:52:25 +01:00
+ "//" filepath shortcut in Build.php
+ 'getContentFunc' option in Source.php for lazy loading content only when needed (e.g. from DB)
This commit is contained in:
parent
d38f3d0219
commit
d6c933e80d
@ -86,8 +86,13 @@ class Minify_Build {
|
|||||||
foreach ((array)$sources as $source) {
|
foreach ((array)$sources as $source) {
|
||||||
if ($source instanceof Minify_Source) {
|
if ($source instanceof Minify_Source) {
|
||||||
$max = max($max, $source->lastModified);
|
$max = max($max, $source->lastModified);
|
||||||
} elseif (is_string($source) && is_file($source)) {
|
} elseif (is_string($source)) {
|
||||||
$max = max($max, filemtime($source));
|
if (0 === strpos($source, '//')) {
|
||||||
|
$source = $_SERVER['DOCUMENT_ROOT'] . substr($source, 1);
|
||||||
|
}
|
||||||
|
if (is_file($source)) {
|
||||||
|
$max = max($max, filemtime($source));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->lastModified = $max;
|
$this->lastModified = $max;
|
||||||
|
@ -54,7 +54,11 @@ class Minify_Source {
|
|||||||
$this->lastModified = filemtime($spec['filepath']);
|
$this->lastModified = filemtime($spec['filepath']);
|
||||||
} elseif (isset($spec['id'])) {
|
} elseif (isset($spec['id'])) {
|
||||||
$this->_id = 'id::' . $spec['id'];
|
$this->_id = 'id::' . $spec['id'];
|
||||||
$this->_content = $spec['content'];
|
if (isset($spec['content'])) {
|
||||||
|
$this->_content = $spec['content'];
|
||||||
|
} else {
|
||||||
|
$this->_getContentFunc = $spec['getContentFunc'];
|
||||||
|
}
|
||||||
$this->lastModified = isset($spec['lastModified'])
|
$this->lastModified = isset($spec['lastModified'])
|
||||||
? $spec['lastModified']
|
? $spec['lastModified']
|
||||||
: time();
|
: time();
|
||||||
@ -74,9 +78,12 @@ class Minify_Source {
|
|||||||
*/
|
*/
|
||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
return (null !== $this->_content)
|
return (null !== $this->_filepath)
|
||||||
? $this->_content
|
? file_get_contents($this->_filepath)
|
||||||
: file_get_contents($this->_filepath);
|
: ((null !== $this->_content)
|
||||||
|
? $this->_content
|
||||||
|
: call_user_func($this->_getContentFunc, $this->_id)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,6 +150,7 @@ class Minify_Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected $_content = null;
|
protected $_content = null;
|
||||||
|
protected $_getContentFunc = null;
|
||||||
protected $_filepath = null;
|
protected $_filepath = null;
|
||||||
protected $_id = null;
|
protected $_id = null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user