mirror of
https://github.com/mrclay/minify.git
synced 2025-01-17 21:28:14 +01:00
Renamed "tests" to "unit_tests"
Cache/Memcache.php : new! utils.php : a few _Minify utility functions for the "min" app HISTORY : preparation for 2.1 beta
This commit is contained in:
parent
5fc4d15889
commit
8d22e6e33a
10
HISTORY
10
HISTORY
@ -1,5 +1,15 @@
|
||||
Minify Release History
|
||||
|
||||
Version 2.1.0 beta
|
||||
* "min" default app for quick deployment
|
||||
* "debug" mode for revealing original line #s in combined files
|
||||
* Relative URIs in CSS file are fixed automatically
|
||||
* Conditional GETs always supported
|
||||
* Improved CSS/HTML minifiers
|
||||
* New "CSS linearizer" which processes @imports server-side
|
||||
* New memcache storage class (default is files)
|
||||
* Several bug fixes
|
||||
|
||||
Version 2.0.2 beta (2008-06-24)
|
||||
* Fast new cache system. Cached files served almost 3x as fast.
|
||||
* Dropped support of compress encoding (though HTTP_Encoder still supports it)
|
||||
|
126
min/lib/Minify/Cache/Memcache.php
Normal file
126
min/lib/Minify/Cache/Memcache.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Cache_Memcache
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Memcache-based cache class for Minify
|
||||
*
|
||||
* <code>
|
||||
* // fall back to disk caching if memcache can't connect
|
||||
* $memcache = new Memcache;
|
||||
* if ($memcache->connect('localhost', 11211)) {
|
||||
* Minify::setCache(new Minify_Cache_Memcache($memcache));
|
||||
* } else {
|
||||
* Minify::setCache();
|
||||
* }
|
||||
* </code>
|
||||
**/
|
||||
class Minify_Cache_Memcache {
|
||||
|
||||
public function __construct($memcache, $expire = 0)
|
||||
{
|
||||
$this->_mc = $memcache;
|
||||
$this->_exp = $expire;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to cache.
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
public function store($id, $data)
|
||||
{
|
||||
return $this->_mc->set($id, "{$_SERVER['REQUEST_TIME']}|{$data}", 0, $this->_exp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the size of a cache entry
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @return int size in bytes
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? strlen($this->_data)
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a valid cache entry exist?
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @param int $srcMtime mtime of the original source file(s)
|
||||
*
|
||||
* @return bool exists
|
||||
*/
|
||||
public function isValid($id, $srcMtime)
|
||||
{
|
||||
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the cached content to output
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function display($id)
|
||||
{
|
||||
echo $this->_fetch($id)
|
||||
? $this->_data
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cached content
|
||||
*
|
||||
* @param string $id cache id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? $this->_data
|
||||
: '';
|
||||
}
|
||||
|
||||
private $_mc = null;
|
||||
private $_exp = null;
|
||||
|
||||
// PHP memory cache of most recently fetched id
|
||||
private $_lm = null;
|
||||
private $_data = null;
|
||||
private $_id = null;
|
||||
|
||||
/**
|
||||
* Fetch data and timestamp from memcache, store in instance
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
private function _fetch($id)
|
||||
{
|
||||
if ($this->_id === $id) {
|
||||
return true;
|
||||
}
|
||||
$ret = $this->_mc->get($id);
|
||||
if (false === $ret) {
|
||||
$this->_id = null;
|
||||
return false;
|
||||
}
|
||||
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
||||
$this->_id = $id;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Function min_group_uri()
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/lib/Minify/Build.php';
|
||||
|
||||
/**
|
||||
* Get a timestamped URI to a minified resource using the default Minify install
|
||||
*
|
||||
* <code>
|
||||
* <link rel="stylesheet" type="text/css" href="<?php min_group_uri('css'); ?>" />
|
||||
* <script type="text/javascript" src="<?php min_group_uri('js'); ?>"></script>
|
||||
* </code>
|
||||
*
|
||||
* @param string $group a key of the array in groupsConfig.php
|
||||
* @param string $ampersand '&' or '&' (default '&')
|
||||
* @return string
|
||||
*/
|
||||
function min_group_uri($group, $ampersand = '&')
|
||||
{
|
||||
static $gc = false;
|
||||
if (false === $gc) {
|
||||
$gc = (require dirname(__FILE__) . '/groupsConfig.php');
|
||||
}
|
||||
$b = new Minify_Build($gc[$group]);
|
||||
Minify_Build::$ampersand = $ampersand;
|
||||
return $b->uri('/' . basename(dirname(__FILE__)) . '/?g=' . $group);
|
||||
}
|
78
min/utils.php
Normal file
78
min/utils.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Utility functions for generating group URIs in HTML files
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/lib/Minify/Build.php';
|
||||
|
||||
|
||||
/**
|
||||
* Get a timestamped URI to a minified resource using the default Minify install
|
||||
*
|
||||
* <code>
|
||||
* <link rel="stylesheet" type="text/css" href="<?php Minify_groupUri('css'); ?>" />
|
||||
* <script type="text/javascript" src="<?php Minify_groupUri('js'); ?>"></script>
|
||||
* </code>
|
||||
*
|
||||
* @param string $group a key from groupsConfig.php
|
||||
* @param string $ampersand '&' or '&' (default '&')
|
||||
* @return string
|
||||
*/
|
||||
function Minify_groupUri($group, $ampersand = '&')
|
||||
{
|
||||
Minify_Build::$ampersand = $ampersand;
|
||||
return _Minify_getBuild($group)->uri('/' . basename(dirname(__FILE__)) . '/?g=' . $group);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the last modification time of the source js/css files used by Minify to
|
||||
* build the page.
|
||||
*
|
||||
* If you're caching the output of Minify_groupUri() on disk, you'll want
|
||||
* to rebuild the file if it's older than this value.
|
||||
*
|
||||
* <code>
|
||||
* // simplistic HTML cache system
|
||||
* $file = '/path/to/cache/file';
|
||||
* if (! file_exists($file) || filemtime($file) < Minify_groupsMtime(array('js', 'css'))) {
|
||||
* // (re)build cache
|
||||
* $page = buildPage(); // this calls Minify_groupUri() for js and css
|
||||
* file_put_contents($file, $page);
|
||||
* echo $page;
|
||||
* exit();
|
||||
* }
|
||||
* readfile($file);
|
||||
* </code>
|
||||
*
|
||||
* @param array $groups an array of keys from groupsConfig.php
|
||||
* @return int
|
||||
*/
|
||||
function Minify_groupsMtime($groups)
|
||||
{
|
||||
$max = 0;
|
||||
foreach ((array)$groups as $group) {
|
||||
$max = max($max, _Minify_getBuild($group)->lastModified);
|
||||
}
|
||||
return $max;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group a key from groupsConfig.php
|
||||
* @return Minify_Build
|
||||
* @private
|
||||
*/
|
||||
function _Minify_getBuild($group)
|
||||
{
|
||||
static $builds = array();
|
||||
static $cg = false;
|
||||
if (false === $gc) {
|
||||
$gc = (require dirname(__FILE__) . '/groupsConfig.php');
|
||||
}
|
||||
if (! isset($builds[$group])) {
|
||||
$builds[$group] = new Minify_Build($gc[$group]);
|
||||
}
|
||||
return $builds[$group];
|
||||
}
|
Before Width: | Height: | Size: 202 B After Width: | Height: | Size: 202 B |
@ -1,18 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
|
||||
<head>
|
||||
<title>Test minify.php</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Test minify.php</h1>
|
||||
|
||||
<ul>
|
||||
|
||||
<li><a href="minify.php?files=../test/_test_files/js/before.js">?files=../test/_test_files/js/before.js</a></li>
|
||||
<li><a href="minify.php?files=../test/_test_files/js/before.js,../test/_test_files/minify/QueryString.js">?files=../test/_test_files/js/before.js,../test/_test_files/minify/QueryString.js</a></li>
|
||||
<li><a href="minify.php?files=../test/_test_files/css/paths.css">?files=../test/_test_files/css/paths.css</a> (Note that relative URIs in path.css have been rewritten to point to the same location as if paths.css were linked directly.)</li>
|
||||
<li><a href="minify.php?files=../test/_test_files/css/paths.css,../test/_test_files/css/styles.css">?files=../test/_test_files/css/paths.css,../test/_test_files/css/styles.css</a></li>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
require '../config.php'; // just to set include_path
|
||||
require 'Minify.php';
|
||||
|
||||
Minify::serve('Version1');
|
Loading…
x
Reference in New Issue
Block a user