mirror of
https://github.com/mrclay/minify.git
synced 2025-08-28 08:10:14 +02:00
Large restructuring
Moves all dependency building into App bootstrap.php returns an App instance The app loads config files as necessary Moves logging to Monolog Moves HTTP digest auth to packagist component Rely on sys_get_temp_dir Env hosts $_POST and allows defaults when reading HTML helper uses the App and can handle less files Source factory assumes strings are filenames Fixes JsClosureCompilerTest::test6 (API now handles ES5 by default) Exclude JsClosureCompilerTest due to API limitations config.php can now return a Minify\Config object Variables set in config.php are now moved to a `Minify\Config` object, allowing better static analysis. The `zlib.output_compression` set is moved into `Minify::serve`.
This commit is contained in:
@@ -4,15 +4,42 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Minify_Cache_File implements Minify_CacheInterface {
|
||||
|
||||
public function __construct($path = '', $fileLocking = false)
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $locking;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param bool $fileLocking
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function __construct($path = '', $fileLocking = false, LoggerInterface $logger = null)
|
||||
{
|
||||
if (! $path) {
|
||||
$path = self::tmp();
|
||||
$path = sys_get_temp_dir();
|
||||
}
|
||||
$this->_locking = $fileLocking;
|
||||
$this->_path = $path;
|
||||
$this->locking = $fileLocking;
|
||||
$this->path = $path;
|
||||
|
||||
if (!$logger) {
|
||||
$logger = new \Monolog\Logger('minify');
|
||||
}
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,18 +53,17 @@ class Minify_Cache_File implements Minify_CacheInterface {
|
||||
*/
|
||||
public function store($id, $data)
|
||||
{
|
||||
$flag = $this->_locking
|
||||
$flag = $this->locking
|
||||
? LOCK_EX
|
||||
: null;
|
||||
$file = $this->_path . '/' . $id;
|
||||
$file = $this->path . '/' . $id;
|
||||
if (! @file_put_contents($file, $data, $flag)) {
|
||||
$this->_log("Minify_Cache_File: Write failed to '$file'");
|
||||
$this->logger->warning("Minify_Cache_File: Write failed to '$file'");
|
||||
}
|
||||
// write control
|
||||
if ($data !== $this->fetch($id)) {
|
||||
@unlink($file);
|
||||
$this->_log("Minify_Cache_File: Post-write read failed for '$file'");
|
||||
|
||||
$this->logger->warning("Minify_Cache_File: Post-write read failed for '$file'");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -53,7 +79,7 @@ class Minify_Cache_File implements Minify_CacheInterface {
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
return filesize($this->_path . '/' . $id);
|
||||
return filesize($this->path . '/' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +93,7 @@ class Minify_Cache_File implements Minify_CacheInterface {
|
||||
*/
|
||||
public function isValid($id, $srcMtime)
|
||||
{
|
||||
$file = $this->_path . '/' . $id;
|
||||
$file = $this->path . '/' . $id;
|
||||
|
||||
return (is_file($file) && (filemtime($file) >= $srcMtime));
|
||||
}
|
||||
@@ -79,14 +105,14 @@ class Minify_Cache_File implements Minify_CacheInterface {
|
||||
*/
|
||||
public function display($id)
|
||||
{
|
||||
if ($this->_locking) {
|
||||
$fp = fopen($this->_path . '/' . $id, 'rb');
|
||||
if ($this->locking) {
|
||||
$fp = fopen($this->path . '/' . $id, 'rb');
|
||||
flock($fp, LOCK_SH);
|
||||
fpassthru($fp);
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
} else {
|
||||
readfile($this->_path . '/' . $id);
|
||||
readfile($this->path . '/' . $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +125,8 @@ class Minify_Cache_File implements Minify_CacheInterface {
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
if ($this->_locking) {
|
||||
$fp = fopen($this->_path . '/' . $id, 'rb');
|
||||
if ($this->locking) {
|
||||
$fp = fopen($this->path . '/' . $id, 'rb');
|
||||
if (!$fp) {
|
||||
return false;
|
||||
}
|
||||
@@ -111,7 +137,7 @@ class Minify_Cache_File implements Minify_CacheInterface {
|
||||
|
||||
return $ret;
|
||||
} else {
|
||||
return file_get_contents($this->_path . '/' . $id);
|
||||
return file_get_contents($this->path . '/' . $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,81 +148,30 @@ class Minify_Cache_File implements Minify_CacheInterface {
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->_path;
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a usable temp directory
|
||||
*
|
||||
* Adapted from Solar/Dir.php
|
||||
* @author Paul M. Jones <pmjones@solarphp.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php BSD
|
||||
* @link http://solarphp.com/trac/core/browser/trunk/Solar/Dir.php
|
||||
*
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
public static function tmp()
|
||||
{
|
||||
static $tmp = null;
|
||||
if (! $tmp) {
|
||||
$tmp = function_exists('sys_get_temp_dir')
|
||||
? sys_get_temp_dir()
|
||||
: self::_tmp();
|
||||
$tmp = rtrim($tmp, DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the OS-specific directory for temporary files
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@solarphp.com>
|
||||
* @license http://opensource.org/licenses/bsd-license.php BSD
|
||||
* @link http://solarphp.com/trac/core/browser/trunk/Solar/Dir.php
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function _tmp()
|
||||
{
|
||||
// non-Windows system?
|
||||
if (strtolower(substr(PHP_OS, 0, 3)) != 'win') {
|
||||
$tmp = empty($_ENV['TMPDIR']) ? getenv('TMPDIR') : $_ENV['TMPDIR'];
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
} else {
|
||||
return '/tmp';
|
||||
}
|
||||
}
|
||||
// Windows 'TEMP'
|
||||
$tmp = empty($_ENV['TEMP']) ? getenv('TEMP') : $_ENV['TEMP'];
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
}
|
||||
// Windows 'TMP'
|
||||
$tmp = empty($_ENV['TMP']) ? getenv('TMP') : $_ENV['TMP'];
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
}
|
||||
// Windows 'windir'
|
||||
$tmp = empty($_ENV['windir']) ? getenv('windir') : $_ENV['windir'];
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
}
|
||||
// final fallback for Windows
|
||||
return getenv('SystemRoot') . '\\temp';
|
||||
trigger_error(__METHOD__ . ' is deprecated in Minfy 3.0', E_USER_DEPRECATED);
|
||||
return sys_get_temp_dir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message to the Minify logger
|
||||
* @param string $msg
|
||||
* @return null
|
||||
* @deprecated Use $this->logger
|
||||
*/
|
||||
protected function _log($msg)
|
||||
{
|
||||
Minify_Logger::log($msg);
|
||||
trigger_error(__METHOD__ . ' is deprecated in Minify 3.0.', E_USER_DEPRECATED);
|
||||
$this->logger->warning($msg);
|
||||
}
|
||||
|
||||
private $_path = null;
|
||||
private $_locking = null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user