Skip to content

Commit

Permalink
Switched to composer based CSS minification installation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Jan 4, 2017
1 parent 95055da commit 78525ad
Show file tree
Hide file tree
Showing 220 changed files with 25 additions and 21,032 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"type" : "library",
"require": {
"php": ">=5.3.0",
"vlucas/phpdotenv": "^2.4"
"vlucas/phpdotenv": "^2.4",
"mrclay/minify": "^2.3"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
20 changes: 5 additions & 15 deletions squeezr/conf/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,11 @@
define('SQUEEZR_CSS', true);

/**
* CSS minification provider
* CSS minification
*
* Enter the class name of the CSS minification provider you want to use. The class must be found
* inside a file with the same name (UpperCamelCased plus .php extension) located in the folder
* Tollwerk\Squeezr\Css\Minifier, and it must implement the interface Tollwerk\Squeezr\Css\Minifier.
* Please specify if you want the CSS output to be minified. There's no reason to disable CSS
* minification other than development purposes.
*
* Currently only "Minify" as a minification provider is implemented, and squeezr comes with a
* copy of Minify preinstalled (you can find it under SQUEEZR_ROOT/plugins/minify). Minify is a
* great project of it's own, please visit it at it's homepage or at it's GitHub repository:
*
* @link https://code.google.com/p/minify/
* @github https://github.com/mrclay/minify
*
* If you do not want to use CSS minification provide NULL here.
*
* @var string
* @var boolean
*/
define('SQUEEZR_CSS_MINIFICATION_PROVIDER', 'Minify');
define('SQUEEZR_CSS_MINIFY', true);
22 changes: 10 additions & 12 deletions squeezr/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
* @version 1.0b
*/

use Tollwerk\Squeezr\Cleaner;
use Tollwerk\Squeezr\Css;
use Tollwerk\Squeezr\Image;

// Require the composer autoloader
require_once __DIR__.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php';

// If a squeezr engine has been requested and a file to process is given
if (!empty($_GET['engine']) && !empty($_GET['source'])) {
switch ($_GET['engine']) {
Expand All @@ -36,11 +43,8 @@
// If the CSS engine hasn't been disabled temporarily
if (SQUEEZR_CSS) {

// Include the CSS engine itself
require_once __DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Tollwerk'.DIRECTORY_SEPARATOR.'Squeezr'.DIRECTORY_SEPARATOR.'Css.php';

// Squeeze, cache and send the CSS file
\Tollwerk\Squeezr\Css::instance($_GET['source'])->send();
Css::instance($_GET['source'])->send();

// Else: Don't care about caching and deliver the original file
} else {
Expand All @@ -58,11 +62,8 @@
// If the image engine hasn't been disabled temporarily
if (SQUEEZR_IMAGE) {

// Include the image engine itself
require_once __DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Tollwerk'.DIRECTORY_SEPARATOR.'Squeezr'.DIRECTORY_SEPARATOR.'Image.php';

// Squeeze, cache and send the image file
\Tollwerk\Squeezr\Image::instance($_GET['source'])->send();
Image::instance($_GET['source'])->send();

// Else: Don't care about caching and deliver the original file
} else {
Expand All @@ -79,11 +80,8 @@
// Include the common configuration
require_once __DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'common.php';

// Include the cache cleaner engine
require_once __DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Tollwerk'.DIRECTORY_SEPARATOR.'Squeezr'.DIRECTORY_SEPARATOR.'Cleaner.php';

// Clean the cache root directory
\Tollwerk\Squeezr\Cleaner::instance(SQUEEZR_CACHEROOT)->clean();
Cleaner::instance(SQUEEZR_CACHEROOT)->clean();

// Respond with an empty content
header('HTTP/1.1 204 No Content');
Expand Down
32 changes: 4 additions & 28 deletions squeezr/lib/Tollwerk/Squeezr/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

namespace Tollwerk\Squeezr;

// Require the abstract engine base class
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'Squeezr.php';
use Tollwerk\Squeezr\Css\Minifier\Minify;

/**
* CSS engine / media query proxy
Expand Down Expand Up @@ -611,32 +610,9 @@ protected function _minify($css)
*/
protected function _compileCacheClassCode()
{

// Register a minification provider (if any)
if (SQUEEZR_CSS_MINIFICATION_PROVIDER) {
$minificationProvider = ucfirst(strtolower(SQUEEZR_CSS_MINIFICATION_PROVIDER));

// If the minification provider class file doesn't exist: error
if (!@is_readable(__DIR__.DIRECTORY_SEPARATOR.'Css'.DIRECTORY_SEPARATOR.'Minifier'.DIRECTORY_SEPARATOR.$minificationProvider.'.php')) {
require_once __DIR__.DIRECTORY_SEPARATOR.'Css'.DIRECTORY_SEPARATOR.'Minifier'.DIRECTORY_SEPARATOR.'Exception.php';
throw new \Tollwerk\Squeezr\Css\Minifier\Exception(sprintf(\Tollwerk\Squeezr\Css\Minifier\Exception::INVALID_MINIFICATION_PROVIDER_MSG,
SQUEEZR_CSS_MINIFICATION_PROVIDER),
\Tollwerk\Squeezr\Css\Minifier\Exception::INVALID_MINIFICATION_PROVIDER);
}

// Require and verify the minification provider
require_once __DIR__.DIRECTORY_SEPARATOR.'Css'.DIRECTORY_SEPARATOR.'Minifier.php';
require_once __DIR__.DIRECTORY_SEPARATOR.'Css'.DIRECTORY_SEPARATOR.'Minifier'.DIRECTORY_SEPARATOR.$minificationProvider.'.php';
$minificationProvider = '\\Tollwerk\\Squeezr\\Css\\Minifier\\'.$minificationProvider;
if (!@class_exists($minificationProvider, false) || !is_subclass_of($minificationProvider,
'\\Tollwerk\\Squeezr\\Css\\Minifier')
) {
throw new \Tollwerk\Squeezr\Css\Minifier\Exception(sprintf(\Tollwerk\Squeezr\Css\Minifier\Exception::INVALID_MINIFICATION_PROVIDER_MSG,
SQUEEZR_CSS_MINIFICATION_PROVIDER),
\Tollwerk\Squeezr\Css\Minifier\Exception::INVALID_MINIFICATION_PROVIDER);
}

$this->_minifier = new $minificationProvider();
// Instantiate a minification provider (if enabled)
if (SQUEEZR_CSS_MINIFY) {
$this->_minifier = new Minify();
}

// Parse the CSS file and extract breakpoint and CSS block info
Expand Down
2 changes: 0 additions & 2 deletions squeezr/lib/Tollwerk/Squeezr/Css/Minifier/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

namespace Tollwerk\Squeezr\Css\Minifier;

require_once dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR.'Exception.php';

/**
* Minification provider exception
*
Expand Down
30 changes: 0 additions & 30 deletions squeezr/lib/Tollwerk/Squeezr/Css/Minifier/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

namespace Tollwerk\Squeezr\Css\Minifier;

// Require the minification provider interface
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'Minifier.php';

// Require the minification provider exception
require_once __DIR__.DIRECTORY_SEPARATOR.'Exception.php';

/**
* Minify minification provider
*
Expand All @@ -32,30 +26,6 @@
*/
class Minify implements \Tollwerk\Squeezr\Css\Minifier
{

/**
* Constructor
*
* @throws \Tollwerk\Squeezr\Css\Minifier\Exception If the minify installation is invalid
* @todo joschi Use Minify_CSS instead of Minify_CSS_Compressor in order to get some options (necessary?)
*/
public function __construct()
{

// Check if minify is installed properly
if (!@is_readable(SQUEEZR_PLUGINS.'minify'.DIRECTORY_SEPARATOR.'min'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Minify'.DIRECTORY_SEPARATOR.'CSS'.DIRECTORY_SEPARATOR.'Compressor.php')) {
throw new \Tollwerk\Squeezr\Css\Minifier\Exception(sprintf(\Tollwerk\Squeezr\Css\Minifier\Exception::INVALID_MINIFICATION_PROVIDER_MSG,
'minify'), \Tollwerk\Squeezr\Css\Minifier\Exception::INVALID_MINIFICATION_PROVIDER);
}

// Include and verify the minify compressor class
require_once SQUEEZR_PLUGINS.'minify'.DIRECTORY_SEPARATOR.'min'.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Minify'.DIRECTORY_SEPARATOR.'CSS'.DIRECTORY_SEPARATOR.'Compressor.php';
if (!@class_exists('\\Minify_CSS_Compressor', false)) {
throw new \Tollwerk\Squeezr\Css\Minifier\Exception(sprintf(\Tollwerk\Squeezr\Css\Minifier\Exception::INVALID_MINIFICATION_PROVIDER_MSG,
'minify'), \Tollwerk\Squeezr\Css\Minifier\Exception::INVALID_MINIFICATION_PROVIDER);
}
}

/**
* Minify a CSS text
*
Expand Down
5 changes: 1 addition & 4 deletions squeezr/lib/Tollwerk/Squeezr/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

namespace Tollwerk\Squeezr;

// Require the abstract engine base class
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'Squeezr.php';

/**
* Image engine
*
Expand Down Expand Up @@ -486,4 +483,4 @@ protected static function _enableTranparency($image, array $transparentColor = n
imagealphablending($image, false);
imagesavealpha($image, true);
}
}
}
16 changes: 3 additions & 13 deletions squeezr/lib/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* @version 1.0b
*/

// Require the composer autoloader
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php';

// Require the custom common configuration
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'conf'.DIRECTORY_SEPARATOR.'common.php';

// Require the exception base class
require_once __DIR__.DIRECTORY_SEPARATOR.'Tollwerk'.DIRECTORY_SEPARATOR.'Squeezr'.DIRECTORY_SEPARATOR.'Exception.php';

/**
* squeezr cache root
*
Expand All @@ -29,16 +29,6 @@
*/
define('SQUEEZR_CACHEROOT', rtrim(SQUEEZR_ROOT, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);

/**
* squeezr plugin directory
*
* Plugins for squeezr (like CSS minification providers) are put into a directory named "plugins"
* under the squeezr main directory.
*
* @var string
*/
define('SQUEEZR_PLUGINS', rtrim(SQUEEZR_ROOT, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR);

/**
* Active breakpoint definition
*
Expand Down
100 changes: 0 additions & 100 deletions squeezr/plugins/minify/HISTORY.txt

This file was deleted.

26 changes: 0 additions & 26 deletions squeezr/plugins/minify/LICENSE.txt

This file was deleted.

Loading

0 comments on commit 78525ad

Please sign in to comment.