initial commit
This commit is contained in:
7
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/autoload.php
vendored
Normal file
7
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/autoload.php
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitc3499d78139cb5a05b10193198da5145::getLoader();
|
37
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/bin/cssmin
vendored
Normal file
37
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/bin/cssmin
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use tubalmartin\CssMin\Command;
|
||||
|
||||
$autoloadPath = null;
|
||||
$autoloadPaths = array(
|
||||
__DIR__ . '/../../autoload.php',
|
||||
__DIR__ . '/../vendor/autoload.php',
|
||||
__DIR__ . '/vendor/autoload.php'
|
||||
);
|
||||
|
||||
foreach ($autoloadPaths as $file) {
|
||||
if (file_exists($file)) {
|
||||
$autoloadPath = $file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unset($file);
|
||||
unset($autoloadPaths);
|
||||
|
||||
if (is_null($autoloadPath)) {
|
||||
fwrite(
|
||||
STDERR,
|
||||
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
|
||||
' composer install' . PHP_EOL . PHP_EOL .
|
||||
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
|
||||
);
|
||||
die(1);
|
||||
}
|
||||
|
||||
require $autoloadPath;
|
||||
|
||||
unset($autoloadPath);
|
||||
|
||||
Command::main();
|
45
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/bin/minifycss
vendored
Normal file
45
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/bin/minifycss
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
use MatthiasMullie\Minify;
|
||||
|
||||
// command line utility to minify CSS
|
||||
if (file_exists(__DIR__ . '/../../../autoload.php')) {
|
||||
// if composer install
|
||||
require_once __DIR__ . '/../../../autoload.php';
|
||||
} else {
|
||||
require_once __DIR__ . '/../src/Minify.php';
|
||||
require_once __DIR__ . '/../src/CSS.php';
|
||||
require_once __DIR__ . '/../src/Exception.php';
|
||||
}
|
||||
|
||||
error_reporting(E_ALL);
|
||||
// check PHP setup for cli arguments
|
||||
if (!isset($_SERVER['argv']) && !isset($argv)) {
|
||||
fwrite(STDERR, 'Please enable the "register_argc_argv" directive in your php.ini' . PHP_EOL);
|
||||
exit(1);
|
||||
} elseif (!isset($argv)) {
|
||||
$argv = $_SERVER['argv'];
|
||||
}
|
||||
// check if path to file given
|
||||
if (!isset($argv[1])) {
|
||||
fwrite(STDERR, 'Argument expected: path to file' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
// check if script run in cli environment
|
||||
if ('cli' !== php_sapi_name()) {
|
||||
fwrite(STDERR, $argv[1] . ' must be run in the command line' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
// check if source file exists
|
||||
if (!file_exists($argv[1])) {
|
||||
fwrite(STDERR, 'Source file "' . $argv[1] . '" not found' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
$minifier = new Minify\CSS($argv[1]);
|
||||
echo $minifier->minify();
|
||||
} catch (Exception $e) {
|
||||
fwrite(STDERR, $e->getMessage(), PHP_EOL);
|
||||
exit(1);
|
||||
}
|
45
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/bin/minifyjs
vendored
Normal file
45
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/bin/minifyjs
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
use MatthiasMullie\Minify;
|
||||
|
||||
// command line utility to minify JS
|
||||
if (file_exists(__DIR__ . '/../../../autoload.php')) {
|
||||
// if composer install
|
||||
require_once __DIR__ . '/../../../autoload.php';
|
||||
} else {
|
||||
require_once __DIR__ . '/../src/Minify.php';
|
||||
require_once __DIR__ . '/../src/JS.php';
|
||||
require_once __DIR__ . '/../src/Exception.php';
|
||||
}
|
||||
|
||||
error_reporting(E_ALL);
|
||||
// check PHP setup for cli arguments
|
||||
if (!isset($_SERVER['argv']) && !isset($argv)) {
|
||||
fwrite(STDERR, 'Please enable the "register_argc_argv" directive in your php.ini' . PHP_EOL);
|
||||
exit(1);
|
||||
} elseif (!isset($argv)) {
|
||||
$argv = $_SERVER['argv'];
|
||||
}
|
||||
// check if path to file given
|
||||
if (!isset($argv[1])) {
|
||||
fwrite(STDERR, 'Argument expected: path to file' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
// check if script run in cli environment
|
||||
if ('cli' !== php_sapi_name()) {
|
||||
fwrite(STDERR, $argv[1] . ' must be run in the command line' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
// check if source file exists
|
||||
if (!file_exists($argv[1])) {
|
||||
fwrite(STDERR, 'Source file "' . $argv[1] . '" not found' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
$minifier = new Minify\JS($argv[1]);
|
||||
echo $minifier->minify();
|
||||
} catch (Exception $e) {
|
||||
fwrite(STDERR, $e->getMessage(), PHP_EOL);
|
||||
exit(1);
|
||||
}
|
248
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/bin/plessc
vendored
Normal file
248
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/bin/plessc
vendored
Normal file
@ -0,0 +1,248 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
// Command line utility to compile LESS to STDOUT
|
||||
// Leaf Corcoran <leafot@gmail.com>, 2013
|
||||
|
||||
$exe = array_shift($argv); // remove filename
|
||||
|
||||
$HELP = <<<EOT
|
||||
Usage: $exe [options] input-file [output-file]
|
||||
|
||||
Options include:
|
||||
|
||||
-h, --help Show this message
|
||||
-v Print the version
|
||||
-f=format Set the output format, includes "default", "compressed"
|
||||
-c Keep /* */ comments in output
|
||||
-r Read from STDIN instead of input-file
|
||||
-w Watch input-file, and compile to output-file if it is changed
|
||||
-T Dump formatted parse tree
|
||||
-X Dump raw parse tree
|
||||
|
||||
|
||||
EOT;
|
||||
|
||||
$opts = getopt('hvrwncXTf:', array('help'));
|
||||
while (count($argv) > 0 && preg_match('/^-([-hvrwncXT]$|[f]=)/', $argv[0])) {
|
||||
array_shift($argv);
|
||||
}
|
||||
|
||||
function has() {
|
||||
global $opts;
|
||||
foreach (func_get_args() as $arg) {
|
||||
if (isset($opts[$arg])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (has("h", "help")) {
|
||||
exit($HELP);
|
||||
}
|
||||
|
||||
error_reporting(E_ALL);
|
||||
$path = realpath(dirname(__FILE__)).'/';
|
||||
|
||||
require $path."lessc.inc.php";
|
||||
|
||||
$VERSION = lessc::$VERSION;
|
||||
|
||||
$fa = "Fatal Error: ";
|
||||
function err($msg) {
|
||||
fwrite(STDERR, $msg."\n");
|
||||
}
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
err($fa.$argv[0]." must be run in the command line.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
function make_less($fname = null) {
|
||||
global $opts;
|
||||
$l = new lessc($fname);
|
||||
|
||||
if (has("f")) {
|
||||
$format = $opts["f"];
|
||||
if ($format != "default") $l->setFormatter($format);
|
||||
}
|
||||
|
||||
if (has("c")) {
|
||||
$l->setPreserveComments(true);
|
||||
}
|
||||
|
||||
return $l;
|
||||
}
|
||||
|
||||
function process($data, $import = null) {
|
||||
global $fa;
|
||||
|
||||
$l = make_less();
|
||||
if ($import) $l->importDir = $import;
|
||||
|
||||
try {
|
||||
echo $l->parse($data);
|
||||
exit(0);
|
||||
} catch (exception $ex) {
|
||||
err($fa."\n".str_repeat('=', 20)."\n".
|
||||
$ex->getMessage());
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (has("v")) {
|
||||
exit($VERSION."\n");
|
||||
}
|
||||
|
||||
if (has("r")) {
|
||||
if (!empty($argv)) {
|
||||
$data = $argv[0];
|
||||
} else {
|
||||
$data = "";
|
||||
while (!feof(STDIN)) {
|
||||
$data .= fread(STDIN, 8192);
|
||||
}
|
||||
}
|
||||
exit(process($data));
|
||||
}
|
||||
|
||||
if (has("w")) {
|
||||
// need two files
|
||||
if (!is_file($in = array_shift($argv)) ||
|
||||
null == $out = array_shift($argv))
|
||||
{
|
||||
err($fa.$exe." -w infile outfile");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "Watching ".$in.
|
||||
(has("n") ? ' with notifications' : '').
|
||||
", press Ctrl + c to exit.\n";
|
||||
|
||||
$cache = $in;
|
||||
$last_action = 0;
|
||||
while (true) {
|
||||
clearstatcache();
|
||||
|
||||
// check if anything has changed since last fail
|
||||
$updated = false;
|
||||
if (is_array($cache)) {
|
||||
foreach ($cache['files'] as $fname=>$_) {
|
||||
if (filemtime($fname) > $last_action) {
|
||||
$updated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else $updated = true;
|
||||
|
||||
// try to compile it
|
||||
if ($updated) {
|
||||
$last_action = time();
|
||||
|
||||
try {
|
||||
$cache = lessc::cexecute($cache);
|
||||
echo "Writing updated file: ".$out."\n";
|
||||
if (!file_put_contents($out, $cache['compiled'])) {
|
||||
err($fa."Could not write to file ".$out);
|
||||
exit(1);
|
||||
}
|
||||
} catch (exception $ex) {
|
||||
echo "\nFatal Error:\n".str_repeat('=', 20)."\n".
|
||||
$ex->getMessage()."\n\n";
|
||||
|
||||
if (has("n")) {
|
||||
`notify-send -u critical "compile failed" "{$ex->getMessage()}"`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!$fname = array_shift($argv)) {
|
||||
echo $HELP;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
function dumpValue($node, $depth = 0) {
|
||||
if (is_object($node)) {
|
||||
$indent = str_repeat(" ", $depth);
|
||||
$out = array();
|
||||
foreach ($node->props as $prop) {
|
||||
$out[] = $indent . dumpValue($prop, $depth + 1);
|
||||
}
|
||||
$out = implode("\n", $out);
|
||||
if (!empty($node->tags)) {
|
||||
$out = "+ ".implode(", ", $node->tags)."\n".$out;
|
||||
}
|
||||
return $out;
|
||||
} elseif (is_array($node)) {
|
||||
if (empty($node)) return "[]";
|
||||
$type = $node[0];
|
||||
if ($type == "block")
|
||||
return dumpValue($node[1], $depth);
|
||||
|
||||
$out = array();
|
||||
foreach ($node as $value) {
|
||||
$out[] = dumpValue($value, $depth);
|
||||
}
|
||||
return "{ ".implode(", ", $out)." }";
|
||||
} else {
|
||||
if (is_string($node) && preg_match("/[\s,]/", $node)) {
|
||||
return '"'.$node.'"';
|
||||
}
|
||||
return $node; // normal value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function stripValue($o, $toStrip) {
|
||||
if (is_array($o) || is_object($o)) {
|
||||
$isObject = is_object($o);
|
||||
$o = (array)$o;
|
||||
foreach ($toStrip as $removeKey) {
|
||||
if (!empty($o[$removeKey])) {
|
||||
$o[$removeKey] = "*stripped*";
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($o as $k => $v) {
|
||||
$o[$k] = stripValue($v, $toStrip);
|
||||
}
|
||||
|
||||
if ($isObject) {
|
||||
$o = (object)$o;
|
||||
}
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
function dumpWithoutParent($o, $alsoStrip=array()) {
|
||||
$toStrip = array_merge(array("parent"), $alsoStrip);
|
||||
print_r(stripValue($o, $toStrip));
|
||||
}
|
||||
|
||||
try {
|
||||
$less = make_less($fname);
|
||||
if (has("T", "X")) {
|
||||
$parser = new lessc_parser($less, $fname);
|
||||
$tree = $parser->parse(file_get_contents($fname));
|
||||
if (has("X"))
|
||||
$out = print_r($tree, 1);
|
||||
else
|
||||
$out = dumpValue($tree)."\n";
|
||||
} else {
|
||||
$out = $less->parse();
|
||||
}
|
||||
|
||||
if (!$fout = array_shift($argv)) {
|
||||
echo $out;
|
||||
} else {
|
||||
file_put_contents($fout, $out);
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
err($fa.$ex->getMessage());
|
||||
exit(1);
|
||||
}
|
623
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery-blockui/jquery.blockUI.js
vendored
Normal file
623
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery-blockui/jquery.blockUI.js
vendored
Normal file
@ -0,0 +1,623 @@
|
||||
/*!
|
||||
* jQuery blockUI plugin
|
||||
* Version 2.71.0-2020.12.08
|
||||
* Requires jQuery v1.12 or later
|
||||
*
|
||||
* Examples at: http://malsup.com/jquery/block/
|
||||
* Copyright (c) 2007-2013 M. Alsup
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Thanks to Amir-Hossein Sobhi for some excellent contributions!
|
||||
*/
|
||||
|
||||
;(function() {
|
||||
/*jshint eqeqeq:false curly:false latedef:false */
|
||||
"use strict";
|
||||
|
||||
function setup($) {
|
||||
var migrateDeduplicateWarnings = jQuery.migrateDeduplicateWarnings || false;
|
||||
jQuery.migrateDeduplicateWarnings = false;
|
||||
|
||||
$.fn._fadeIn = $.fn.fadeIn;
|
||||
|
||||
var noOp = $.noop || function() {};
|
||||
|
||||
// this bit is to ensure we don't call setExpression when we shouldn't (with extra muscle to handle
|
||||
// confusing userAgent strings on Vista)
|
||||
var msie = /MSIE/.test(navigator.userAgent);
|
||||
var ie6 = /MSIE 6.0/.test(navigator.userAgent) && ! /MSIE 8.0/.test(navigator.userAgent);
|
||||
var mode = document.documentMode || 0;
|
||||
var setExpr = "function" === typeof document.createElement('div').style.setExpression;
|
||||
|
||||
// global $ methods for blocking/unblocking the entire page
|
||||
$.blockUI = function(opts) { install(window, opts); };
|
||||
$.unblockUI = function(opts) { remove(window, opts); };
|
||||
|
||||
// convenience method for quick growl-like notifications (http://www.google.com/search?q=growl)
|
||||
$.growlUI = function(title, message, timeout, onClose) {
|
||||
var $m = $('<div class="growlUI"></div>');
|
||||
if (title) $m.append('<h1>'+title+'</h1>');
|
||||
if (message) $m.append('<h2>'+message+'</h2>');
|
||||
if (timeout === undefined) timeout = 3000;
|
||||
|
||||
// Added by konapun: Set timeout to 30 seconds if this growl is moused over, like normal toast notifications
|
||||
var callBlock = function(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
$.blockUI({
|
||||
message: $m,
|
||||
fadeIn : typeof opts.fadeIn !== 'undefined' ? opts.fadeIn : 700,
|
||||
fadeOut: typeof opts.fadeOut !== 'undefined' ? opts.fadeOut : 1000,
|
||||
timeout: typeof opts.timeout !== 'undefined' ? opts.timeout : timeout,
|
||||
centerY: false,
|
||||
showOverlay: false,
|
||||
onUnblock: onClose,
|
||||
css: $.blockUI.defaults.growlCSS
|
||||
});
|
||||
};
|
||||
|
||||
callBlock();
|
||||
var nonmousedOpacity = $m.css('opacity');
|
||||
$m.on('mouseover', function() {
|
||||
callBlock({
|
||||
fadeIn: 0,
|
||||
timeout: 30000
|
||||
});
|
||||
|
||||
var displayBlock = $('.blockMsg');
|
||||
displayBlock.stop(); // cancel fadeout if it has started
|
||||
displayBlock.fadeTo(300, 1); // make it easier to read the message by removing transparency
|
||||
}).on('mouseout', function() {
|
||||
$('.blockMsg').fadeOut(1000);
|
||||
});
|
||||
// End konapun additions
|
||||
};
|
||||
|
||||
// plugin method for blocking element content
|
||||
$.fn.block = function(opts) {
|
||||
if ( this[0] === window ) {
|
||||
$.blockUI( opts );
|
||||
return this;
|
||||
}
|
||||
var fullOpts = $.extend({}, $.blockUI.defaults, opts || {});
|
||||
this.each(function() {
|
||||
var $el = $(this);
|
||||
if (fullOpts.ignoreIfBlocked && $el.data('blockUI.isBlocked'))
|
||||
return;
|
||||
$el.unblock({ fadeOut: 0 });
|
||||
});
|
||||
|
||||
return this.each(function() {
|
||||
if ($.css(this,'position') == 'static') {
|
||||
this.style.position = 'relative';
|
||||
$(this).data('blockUI.static', true);
|
||||
}
|
||||
this.style.zoom = 1; // force 'hasLayout' in ie
|
||||
install(this, opts);
|
||||
});
|
||||
};
|
||||
|
||||
// plugin method for unblocking element content
|
||||
$.fn.unblock = function(opts) {
|
||||
if ( this[0] === window ) {
|
||||
$.unblockUI( opts );
|
||||
return this;
|
||||
}
|
||||
return this.each(function() {
|
||||
remove(this, opts);
|
||||
});
|
||||
};
|
||||
|
||||
$.blockUI.version = 2.70; // 2nd generation blocking at no extra cost!
|
||||
|
||||
// override these in your code to change the default behavior and style
|
||||
$.blockUI.defaults = {
|
||||
// message displayed when blocking (use null for no message)
|
||||
message: '<h1>Please wait...</h1>',
|
||||
|
||||
title: null, // title string; only used when theme == true
|
||||
draggable: true, // only used when theme == true (requires jquery-ui.js to be loaded)
|
||||
|
||||
theme: false, // set to true to use with jQuery UI themes
|
||||
|
||||
// styles for the message when blocking; if you wish to disable
|
||||
// these and use an external stylesheet then do this in your code:
|
||||
// $.blockUI.defaults.css = {};
|
||||
css: {
|
||||
padding: 0,
|
||||
margin: 0,
|
||||
width: '30%',
|
||||
top: '40%',
|
||||
left: '35%',
|
||||
textAlign: 'center',
|
||||
color: '#000',
|
||||
border: '3px solid #aaa',
|
||||
backgroundColor:'#fff',
|
||||
cursor: 'wait'
|
||||
},
|
||||
|
||||
// minimal style set used when themes are used
|
||||
themedCSS: {
|
||||
width: '30%',
|
||||
top: '40%',
|
||||
left: '35%'
|
||||
},
|
||||
|
||||
// styles for the overlay
|
||||
overlayCSS: {
|
||||
backgroundColor: '#000',
|
||||
opacity: 0.6,
|
||||
cursor: 'wait'
|
||||
},
|
||||
|
||||
// style to replace wait cursor before unblocking to correct issue
|
||||
// of lingering wait cursor
|
||||
cursorReset: 'default',
|
||||
|
||||
// styles applied when using $.growlUI
|
||||
growlCSS: {
|
||||
width: '350px',
|
||||
top: '10px',
|
||||
left: '',
|
||||
right: '10px',
|
||||
border: 'none',
|
||||
padding: '5px',
|
||||
opacity: 0.6,
|
||||
cursor: 'default',
|
||||
color: '#fff',
|
||||
backgroundColor: '#000',
|
||||
'-webkit-border-radius':'10px',
|
||||
'-moz-border-radius': '10px',
|
||||
'border-radius': '10px'
|
||||
},
|
||||
|
||||
// IE issues: 'about:blank' fails on HTTPS and javascript:false is s-l-o-w
|
||||
// (hat tip to Jorge H. N. de Vasconcelos)
|
||||
/*jshint scripturl:true */
|
||||
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank',
|
||||
|
||||
// force usage of iframe in non-IE browsers (handy for blocking applets)
|
||||
forceIframe: false,
|
||||
|
||||
// z-index for the blocking overlay
|
||||
baseZ: 1000,
|
||||
|
||||
// set these to true to have the message automatically centered
|
||||
centerX: true, // <-- only effects element blocking (page block controlled via css above)
|
||||
centerY: true,
|
||||
|
||||
// allow body element to be stetched in ie6; this makes blocking look better
|
||||
// on "short" pages. disable if you wish to prevent changes to the body height
|
||||
allowBodyStretch: true,
|
||||
|
||||
// enable if you want key and mouse events to be disabled for content that is blocked
|
||||
bindEvents: true,
|
||||
|
||||
// be default blockUI will supress tab navigation from leaving blocking content
|
||||
// (if bindEvents is true)
|
||||
constrainTabKey: true,
|
||||
|
||||
// fadeIn time in millis; set to 0 to disable fadeIn on block
|
||||
fadeIn: 200,
|
||||
|
||||
// fadeOut time in millis; set to 0 to disable fadeOut on unblock
|
||||
fadeOut: 400,
|
||||
|
||||
// time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock
|
||||
timeout: 0,
|
||||
|
||||
// disable if you don't want to show the overlay
|
||||
showOverlay: true,
|
||||
|
||||
// if true, focus will be placed in the first available input field when
|
||||
// page blocking
|
||||
focusInput: true,
|
||||
|
||||
// elements that can receive focus
|
||||
focusableElements: ':input:enabled:visible',
|
||||
|
||||
// suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
|
||||
// no longer needed in 2012
|
||||
// applyPlatformOpacityRules: true,
|
||||
|
||||
// callback method invoked when fadeIn has completed and blocking message is visible
|
||||
onBlock: null,
|
||||
|
||||
// callback method invoked when unblocking has completed; the callback is
|
||||
// passed the element that has been unblocked (which is the window object for page
|
||||
// blocks) and the options that were passed to the unblock call:
|
||||
// onUnblock(element, options)
|
||||
onUnblock: null,
|
||||
|
||||
// callback method invoked when the overlay area is clicked.
|
||||
// setting this will turn the cursor to a pointer, otherwise cursor defined in overlayCss will be used.
|
||||
onOverlayClick: null,
|
||||
|
||||
// don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493
|
||||
quirksmodeOffsetHack: 4,
|
||||
|
||||
// class name of the message block
|
||||
blockMsgClass: 'blockMsg',
|
||||
|
||||
// if it is already blocked, then ignore it (don't unblock and reblock)
|
||||
ignoreIfBlocked: false
|
||||
};
|
||||
|
||||
// private data and functions follow...
|
||||
|
||||
var pageBlock = null;
|
||||
var pageBlockEls = [];
|
||||
|
||||
function install(el, opts) {
|
||||
var css, themedCSS;
|
||||
var full = (el == window);
|
||||
var msg = (opts && opts.message !== undefined ? opts.message : undefined);
|
||||
opts = $.extend({}, $.blockUI.defaults, opts || {});
|
||||
|
||||
if (opts.ignoreIfBlocked && $(el).data('blockUI.isBlocked'))
|
||||
return;
|
||||
|
||||
opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
|
||||
css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
|
||||
if (opts.onOverlayClick)
|
||||
opts.overlayCSS.cursor = 'pointer';
|
||||
|
||||
themedCSS = $.extend({}, $.blockUI.defaults.themedCSS, opts.themedCSS || {});
|
||||
msg = msg === undefined ? opts.message : msg;
|
||||
|
||||
// remove the current block (if there is one)
|
||||
if (full && pageBlock)
|
||||
remove(window, {fadeOut:0});
|
||||
|
||||
// if an existing element is being used as the blocking content then we capture
|
||||
// its current place in the DOM (and current display style) so we can restore
|
||||
// it when we unblock
|
||||
if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
|
||||
var node = msg.jquery ? msg[0] : msg;
|
||||
var data = {};
|
||||
$(el).data('blockUI.history', data);
|
||||
data.el = node;
|
||||
data.parent = node.parentNode;
|
||||
data.display = node.style.display;
|
||||
data.position = node.style.position;
|
||||
if (data.parent)
|
||||
data.parent.removeChild(node);
|
||||
}
|
||||
|
||||
$(el).data('blockUI.onUnblock', opts.onUnblock);
|
||||
var z = opts.baseZ;
|
||||
|
||||
// blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
|
||||
// layer1 is the iframe layer which is used to supress bleed through of underlying content
|
||||
// layer2 is the overlay layer which has opacity and a wait cursor (by default)
|
||||
// layer3 is the message content that is displayed while blocking
|
||||
var lyr1, lyr2, lyr3, s;
|
||||
if (msie || opts.forceIframe)
|
||||
lyr1 = $('<iframe class="blockUI" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="'+opts.iframeSrc+'"></iframe>');
|
||||
else
|
||||
lyr1 = $('<div class="blockUI" style="display:none"></div>');
|
||||
|
||||
if (opts.theme)
|
||||
lyr2 = $('<div class="blockUI blockOverlay ui-widget-overlay" style="z-index:'+ (z++) +';display:none"></div>');
|
||||
else
|
||||
lyr2 = $('<div class="blockUI blockOverlay" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');
|
||||
|
||||
if (opts.theme && full) {
|
||||
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:fixed">';
|
||||
if ( opts.title ) {
|
||||
s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || ' ')+'</div>';
|
||||
}
|
||||
s += '<div class="ui-widget-content ui-dialog-content"></div>';
|
||||
s += '</div>';
|
||||
}
|
||||
else if (opts.theme) {
|
||||
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+(z+10)+';display:none;position:absolute">';
|
||||
if ( opts.title ) {
|
||||
s += '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || ' ')+'</div>';
|
||||
}
|
||||
s += '<div class="ui-widget-content ui-dialog-content"></div>';
|
||||
s += '</div>';
|
||||
}
|
||||
else if (full) {
|
||||
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage" style="z-index:'+(z+10)+';display:none;position:fixed"></div>';
|
||||
}
|
||||
else {
|
||||
s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement" style="z-index:'+(z+10)+';display:none;position:absolute"></div>';
|
||||
}
|
||||
lyr3 = $(s);
|
||||
|
||||
// if we have a message, style it
|
||||
if (msg) {
|
||||
if (opts.theme) {
|
||||
lyr3.css(themedCSS);
|
||||
lyr3.addClass('ui-widget-content');
|
||||
}
|
||||
else
|
||||
lyr3.css(css);
|
||||
}
|
||||
|
||||
// style the overlay
|
||||
if (!opts.theme /*&& (!opts.applyPlatformOpacityRules)*/)
|
||||
lyr2.css(opts.overlayCSS);
|
||||
lyr2.css('position', full ? 'fixed' : 'absolute');
|
||||
|
||||
// make iframe layer transparent in IE
|
||||
if (msie || opts.forceIframe)
|
||||
lyr1.css('opacity',0.0);
|
||||
|
||||
//$([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
|
||||
var layers = [lyr1,lyr2,lyr3], $par = full ? $('body') : $(el);
|
||||
$.each(layers, function() {
|
||||
this.appendTo($par);
|
||||
});
|
||||
|
||||
if (opts.theme && opts.draggable && $.fn.draggable) {
|
||||
lyr3.draggable({
|
||||
handle: '.ui-dialog-titlebar',
|
||||
cancel: 'li'
|
||||
});
|
||||
}
|
||||
|
||||
// ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
|
||||
var expr = setExpr && ( "CSS1Compat" !== document.compatMode || $('object,embed', full ? null : el).length > 0);
|
||||
if (ie6 || expr) {
|
||||
// give body 100% height
|
||||
if (full && opts.allowBodyStretch && "CSS1Compat" === document.compatMode)
|
||||
$('html,body').css('height','100%');
|
||||
|
||||
// fix ie6 issue when blocked element has a border width
|
||||
if ((ie6 || "CSS1Compat" !== document.compatMode) && !full) {
|
||||
var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
|
||||
var fixT = t ? '(0 - '+t+')' : 0;
|
||||
var fixL = l ? '(0 - '+l+')' : 0;
|
||||
}
|
||||
|
||||
// simulate fixed position
|
||||
$.each(layers, function(i,o) {
|
||||
var s = o[0].style;
|
||||
s.position = 'absolute';
|
||||
if (i < 2) {
|
||||
if (full)
|
||||
s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - ("CSS1Compat" === document.compatMode?0:'+opts.quirksmodeOffsetHack+') + "px"');
|
||||
else
|
||||
s.setExpression('height','this.parentNode.offsetHeight + "px"');
|
||||
if (full)
|
||||
s.setExpression('width','"CSS1Compat" === document.compatMode && document.documentElement.clientWidth || document.body.clientWidth + "px"');
|
||||
else
|
||||
s.setExpression('width','this.parentNode.offsetWidth + "px"');
|
||||
if (fixL) s.setExpression('left', fixL);
|
||||
if (fixT) s.setExpression('top', fixT);
|
||||
}
|
||||
else if (opts.centerY) {
|
||||
if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
|
||||
s.marginTop = 0;
|
||||
}
|
||||
else if (!opts.centerY && full) {
|
||||
var top = (opts.css && opts.css.top) ? parseInt(opts.css.top, 10) : 0;
|
||||
var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';
|
||||
s.setExpression('top',expression);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// show the message
|
||||
if (msg) {
|
||||
if (opts.theme)
|
||||
lyr3.find('.ui-widget-content').append(msg);
|
||||
else
|
||||
lyr3.append(msg);
|
||||
if (msg.jquery || msg.nodeType)
|
||||
$(msg).show();
|
||||
}
|
||||
|
||||
if ((msie || opts.forceIframe) && opts.showOverlay)
|
||||
lyr1.show(); // opacity is zero
|
||||
if (opts.fadeIn) {
|
||||
var cb = opts.onBlock ? opts.onBlock : noOp;
|
||||
var cb1 = (opts.showOverlay && !msg) ? cb : noOp;
|
||||
var cb2 = msg ? cb : noOp;
|
||||
if (opts.showOverlay)
|
||||
lyr2._fadeIn(opts.fadeIn, cb1);
|
||||
if (msg)
|
||||
lyr3._fadeIn(opts.fadeIn, cb2);
|
||||
}
|
||||
else {
|
||||
if (opts.showOverlay)
|
||||
lyr2.show();
|
||||
if (msg)
|
||||
lyr3.show();
|
||||
if (opts.onBlock)
|
||||
opts.onBlock.bind(lyr3)();
|
||||
}
|
||||
|
||||
// bind key and mouse events
|
||||
bind(1, el, opts);
|
||||
|
||||
if (full) {
|
||||
pageBlock = lyr3[0];
|
||||
pageBlockEls = $(opts.focusableElements,pageBlock);
|
||||
if (opts.focusInput)
|
||||
setTimeout(focus, 20);
|
||||
}
|
||||
else
|
||||
center(lyr3[0], opts.centerX, opts.centerY);
|
||||
|
||||
if (opts.timeout) {
|
||||
// auto-unblock
|
||||
var to = setTimeout(function() {
|
||||
if (full)
|
||||
$.unblockUI(opts);
|
||||
else
|
||||
$(el).unblock(opts);
|
||||
}, opts.timeout);
|
||||
$(el).data('blockUI.timeout', to);
|
||||
}
|
||||
}
|
||||
|
||||
// remove the block
|
||||
function remove(el, opts) {
|
||||
var count;
|
||||
var full = (el == window);
|
||||
var $el = $(el);
|
||||
var data = $el.data('blockUI.history');
|
||||
var to = $el.data('blockUI.timeout');
|
||||
if (to) {
|
||||
clearTimeout(to);
|
||||
$el.removeData('blockUI.timeout');
|
||||
}
|
||||
opts = $.extend({}, $.blockUI.defaults, opts || {});
|
||||
bind(0, el, opts); // unbind events
|
||||
|
||||
if (opts.onUnblock === null) {
|
||||
opts.onUnblock = $el.data('blockUI.onUnblock');
|
||||
$el.removeData('blockUI.onUnblock');
|
||||
}
|
||||
|
||||
var els;
|
||||
if (full) // crazy selector to handle odd field errors in ie6/7
|
||||
els = $('body').children().filter('.blockUI').add('body > .blockUI');
|
||||
else
|
||||
els = $el.find('>.blockUI');
|
||||
|
||||
// fix cursor issue
|
||||
if ( opts.cursorReset ) {
|
||||
if ( els.length > 1 )
|
||||
els[1].style.cursor = opts.cursorReset;
|
||||
if ( els.length > 2 )
|
||||
els[2].style.cursor = opts.cursorReset;
|
||||
}
|
||||
|
||||
if (full)
|
||||
pageBlock = pageBlockEls = null;
|
||||
|
||||
if (opts.fadeOut) {
|
||||
count = els.length;
|
||||
els.stop().fadeOut(opts.fadeOut, function() {
|
||||
if ( --count === 0)
|
||||
reset(els,data,opts,el);
|
||||
});
|
||||
}
|
||||
else
|
||||
reset(els, data, opts, el);
|
||||
}
|
||||
|
||||
// move blocking element back into the DOM where it started
|
||||
function reset(els,data,opts,el) {
|
||||
var $el = $(el);
|
||||
if ( $el.data('blockUI.isBlocked') )
|
||||
return;
|
||||
|
||||
els.each(function(i,o) {
|
||||
// remove via DOM calls so we don't lose event handlers
|
||||
if (this.parentNode)
|
||||
this.parentNode.removeChild(this);
|
||||
});
|
||||
|
||||
if (data && data.el) {
|
||||
data.el.style.display = data.display;
|
||||
data.el.style.position = data.position;
|
||||
data.el.style.cursor = 'default'; // #59
|
||||
if (data.parent)
|
||||
data.parent.appendChild(data.el);
|
||||
$el.removeData('blockUI.history');
|
||||
}
|
||||
|
||||
if ($el.data('blockUI.static')) {
|
||||
$el.css('position', 'static'); // #22
|
||||
}
|
||||
|
||||
if (typeof opts.onUnblock == 'function')
|
||||
opts.onUnblock(el,opts);
|
||||
|
||||
// fix issue in Safari 6 where block artifacts remain until reflow
|
||||
var body = $(document.body), w = body.width(), cssW = body[0].style.width;
|
||||
body.width(w-1).width(w);
|
||||
body[0].style.width = cssW;
|
||||
}
|
||||
|
||||
// bind/unbind the handler
|
||||
function bind(b, el, opts) {
|
||||
var full = el == window, $el = $(el);
|
||||
|
||||
// don't bother unbinding if there is nothing to unbind
|
||||
if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))
|
||||
return;
|
||||
|
||||
$el.data('blockUI.isBlocked', b);
|
||||
|
||||
// don't bind events when overlay is not in use or if bindEvents is false
|
||||
if (!full || !opts.bindEvents || (b && !opts.showOverlay))
|
||||
return;
|
||||
|
||||
// bind anchors and inputs for mouse and key events
|
||||
var events = 'mousedown mouseup keydown keypress keyup touchstart touchend touchmove';
|
||||
if (b)
|
||||
$(document).on(events, opts, handler);
|
||||
else
|
||||
$(document).off(events, handler);
|
||||
|
||||
// former impl...
|
||||
// var $e = $('a,:input');
|
||||
// b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);
|
||||
}
|
||||
|
||||
// event handler to suppress keyboard/mouse events when blocking
|
||||
function handler(e) {
|
||||
// allow tab navigation (conditionally)
|
||||
if (e.type === 'keydown' && e.keyCode && e.keyCode == 9) {
|
||||
if (pageBlock && e.data.constrainTabKey) {
|
||||
var els = pageBlockEls;
|
||||
var fwd = !e.shiftKey && e.target === els[els.length-1];
|
||||
var back = e.shiftKey && e.target === els[0];
|
||||
if (fwd || back) {
|
||||
setTimeout(function(){focus(back);},10);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
var opts = e.data;
|
||||
var target = $(e.target);
|
||||
if (target.hasClass('blockOverlay') && opts.onOverlayClick)
|
||||
opts.onOverlayClick(e);
|
||||
|
||||
// allow events within the message content
|
||||
if (target.parents('div.' + opts.blockMsgClass).length > 0)
|
||||
return true;
|
||||
|
||||
// allow events for content that is not being blocked
|
||||
return target.parents().children().filter('div.blockUI').length === 0;
|
||||
}
|
||||
|
||||
function focus(back) {
|
||||
if (!pageBlockEls)
|
||||
return;
|
||||
var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
|
||||
if (e)
|
||||
e.focus();
|
||||
}
|
||||
|
||||
function center(el, x, y) {
|
||||
var p = el.parentNode, s = el.style;
|
||||
var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
|
||||
var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
|
||||
if (x) s.left = l > 0 ? (l+'px') : '0';
|
||||
if (y) s.top = t > 0 ? (t+'px') : '0';
|
||||
}
|
||||
|
||||
function sz(el, p) {
|
||||
return parseInt($.css(el,p),10)||0;
|
||||
}
|
||||
jQuery.migrateDeduplicateWarnings = migrateDeduplicateWarnings;
|
||||
}
|
||||
|
||||
|
||||
/*global define:true */
|
||||
if (typeof define === 'function' && define.amd && define.amd.jQuery) {
|
||||
define(['jquery'], setup);
|
||||
} else {
|
||||
setup(jQuery);
|
||||
}
|
||||
|
||||
})();
|
10881
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.js
vendored
Normal file
10881
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.min.js
vendored
Normal file
2
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.min.map
vendored
Normal file
1
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.min.map
vendored
Normal file
File diff suppressed because one or more lines are too long
8782
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.slim.js
vendored
Normal file
8782
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.slim.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.slim.min.js
vendored
Normal file
2
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.slim.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.slim.min.map
vendored
Normal file
1
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/components/jquery/jquery.slim.min.map
vendored
Normal file
File diff suppressed because one or more lines are too long
481
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/ClassLoader.php
vendored
Normal file
481
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/ClassLoader.php
vendored
Normal file
@ -0,0 +1,481 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @see https://www.php-fig.org/psr/psr-0/
|
||||
* @see https://www.php-fig.org/psr/psr-4/
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
private $vendorDir;
|
||||
|
||||
// PSR-4
|
||||
private $prefixLengthsPsr4 = array();
|
||||
private $prefixDirsPsr4 = array();
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
private $prefixesPsr0 = array();
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
private $useIncludePath = false;
|
||||
private $classMap = array();
|
||||
private $classMapAuthoritative = false;
|
||||
private $missingClasses = array();
|
||||
private $apcuPrefix;
|
||||
|
||||
private static $registeredLoaders = array();
|
||||
|
||||
public function __construct($vendorDir = null)
|
||||
{
|
||||
$this->vendorDir = $vendorDir;
|
||||
}
|
||||
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $classMap Class to filename map
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-4 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 base directories
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
||||
*
|
||||
* @param string|null $apcuPrefix
|
||||
*/
|
||||
public function setApcuPrefix($apcuPrefix)
|
||||
{
|
||||
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The APCu prefix in use, or null if APCu caching is not enabled.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getApcuPrefix()
|
||||
{
|
||||
return $this->apcuPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
|
||||
if (null === $this->vendorDir) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($prepend) {
|
||||
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
|
||||
} else {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
self::$registeredLoaders[$this->vendorDir] = $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
|
||||
if (null !== $this->vendorDir) {
|
||||
unset(self::$registeredLoaders[$this->vendorDir]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return true|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
||||
return false;
|
||||
}
|
||||
if (null !== $this->apcuPrefix) {
|
||||
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
||||
if ($hit) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if (false === $file && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if (null !== $this->apcuPrefix) {
|
||||
apcu_add($this->apcuPrefix.$class, $file);
|
||||
}
|
||||
|
||||
if (false === $file) {
|
||||
// Remember that this class does not exist.
|
||||
$this->missingClasses[$class] = true;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently registered loaders indexed by their corresponding vendor directories.
|
||||
*
|
||||
* @return self[]
|
||||
*/
|
||||
public static function getRegisteredLoaders()
|
||||
{
|
||||
return self::$registeredLoaders;
|
||||
}
|
||||
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
$subPath = $class;
|
||||
while (false !== $lastPos = strrpos($subPath, '\\')) {
|
||||
$subPath = substr($subPath, 0, $lastPos);
|
||||
$search = $subPath . '\\';
|
||||
if (isset($this->prefixDirsPsr4[$search])) {
|
||||
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
|
||||
foreach ($this->prefixDirsPsr4[$search] as $dir) {
|
||||
if (file_exists($file = $dir . $pathEnd)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*/
|
||||
function includeFile($file)
|
||||
{
|
||||
include $file;
|
||||
}
|
337
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/InstalledVersions.php
vendored
Normal file
337
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/InstalledVersions.php
vendored
Normal file
@ -0,0 +1,337 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer;
|
||||
|
||||
use Composer\Autoload\ClassLoader;
|
||||
use Composer\Semver\VersionParser;
|
||||
|
||||
/**
|
||||
* This class is copied in every Composer installed project and available to all
|
||||
*
|
||||
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
||||
*
|
||||
* To require it's presence, you can require `composer-runtime-api ^2.0`
|
||||
*/
|
||||
class InstalledVersions
|
||||
{
|
||||
private static $installed;
|
||||
private static $canGetVendors;
|
||||
private static $installedByVendor = array();
|
||||
|
||||
/**
|
||||
* Returns a list of all package names which are present, either by being installed, replaced or provided
|
||||
*
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackages()
|
||||
{
|
||||
$packages = array();
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
$packages[] = array_keys($installed['versions']);
|
||||
}
|
||||
|
||||
if (1 === \count($packages)) {
|
||||
return $packages[0];
|
||||
}
|
||||
|
||||
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all package names with a specific type e.g. 'library'
|
||||
*
|
||||
* @param string $type
|
||||
* @return string[]
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public static function getInstalledPackagesByType($type)
|
||||
{
|
||||
$packagesByType = array();
|
||||
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
foreach ($installed['versions'] as $name => $package) {
|
||||
if (isset($package['type']) && $package['type'] === $type) {
|
||||
$packagesByType[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $packagesByType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package is installed
|
||||
*
|
||||
* This also returns true if the package name is provided or replaced by another package
|
||||
*
|
||||
* @param string $packageName
|
||||
* @param bool $includeDevRequirements
|
||||
* @return bool
|
||||
*/
|
||||
public static function isInstalled($packageName, $includeDevRequirements = true)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (isset($installed['versions'][$packageName])) {
|
||||
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given package satisfies a version constraint
|
||||
*
|
||||
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
|
||||
*
|
||||
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
|
||||
*
|
||||
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
|
||||
* @param string $packageName
|
||||
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
|
||||
* @return bool
|
||||
*/
|
||||
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||
{
|
||||
$constraint = $parser->parseConstraints($constraint);
|
||||
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||
|
||||
return $provided->matches($constraint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a version constraint representing all the range(s) which are installed for a given package
|
||||
*
|
||||
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
|
||||
* whether a given version of a package is installed, and not just whether it exists
|
||||
*
|
||||
* @param string $packageName
|
||||
* @return string Version constraint usable with composer/semver
|
||||
*/
|
||||
public static function getVersionRanges($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ranges = array();
|
||||
if (isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
|
||||
}
|
||||
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
|
||||
}
|
||||
if (array_key_exists('provided', $installed['versions'][$packageName])) {
|
||||
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
|
||||
}
|
||||
|
||||
return implode(' || ', $ranges);
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
|
||||
*/
|
||||
public static function getPrettyVersion($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['pretty_version'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
|
||||
*/
|
||||
public static function getReference($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($installed['versions'][$packageName]['reference'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $installed['versions'][$packageName]['reference'];
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $packageName
|
||||
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
|
||||
*/
|
||||
public static function getInstallPath($packageName)
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (!isset($installed['versions'][$packageName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}
|
||||
*/
|
||||
public static function getRootPackage()
|
||||
{
|
||||
$installed = self::getInstalled();
|
||||
|
||||
return $installed[0]['root'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw installed.php data for custom implementations
|
||||
*
|
||||
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
|
||||
* @return array[]
|
||||
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>}
|
||||
*/
|
||||
public static function getRawData()
|
||||
{
|
||||
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = include __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw data of all installed.php which are currently loaded for custom implementations
|
||||
*
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>}>
|
||||
*/
|
||||
public static function getAllRawData()
|
||||
{
|
||||
return self::getInstalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets you reload the static array from another file
|
||||
*
|
||||
* This is only useful for complex integrations in which a project needs to use
|
||||
* this class but then also needs to execute another project's autoloader in process,
|
||||
* and wants to ensure both projects have access to their version of installed.php.
|
||||
*
|
||||
* A typical case would be PHPUnit, where it would need to make sure it reads all
|
||||
* the data it needs from this class, then call reload() with
|
||||
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
|
||||
* the project in which it runs can then also use this class safely, without
|
||||
* interference between PHPUnit's dependencies and the project's dependencies.
|
||||
*
|
||||
* @param array[] $data A vendor/composer/installed.php data set
|
||||
* @return void
|
||||
*
|
||||
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>} $data
|
||||
*/
|
||||
public static function reload($data)
|
||||
{
|
||||
self::$installed = $data;
|
||||
self::$installedByVendor = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>}>
|
||||
*/
|
||||
private static function getInstalled()
|
||||
{
|
||||
if (null === self::$canGetVendors) {
|
||||
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
|
||||
}
|
||||
|
||||
$installed = array();
|
||||
|
||||
if (self::$canGetVendors) {
|
||||
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
|
||||
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir];
|
||||
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
|
||||
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
||||
self::$installed = $installed[count($installed) - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null === self::$installed) {
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = require __DIR__ . '/installed.php';
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
$installed[] = self::$installed;
|
||||
|
||||
return $installed;
|
||||
}
|
||||
}
|
21
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/LICENSE
vendored
Normal file
21
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
Copyright (c) Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
65
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_classmap.php
vendored
Normal file
65
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_classmap.php
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||
'HTTP_ConditionalGet' => $vendorDir . '/mrclay/minify/lib/HTTP/ConditionalGet.php',
|
||||
'HTTP_Encoder' => $vendorDir . '/mrclay/minify/lib/HTTP/Encoder.php',
|
||||
'Minify' => $vendorDir . '/mrclay/minify/lib/Minify.php',
|
||||
'Minify\\App' => $vendorDir . '/mrclay/minify/lib/Minify/App.php',
|
||||
'Minify\\Config' => $vendorDir . '/mrclay/minify/lib/Minify/Config.php',
|
||||
'Minify\\JS\\JShrink' => $vendorDir . '/mrclay/minify/lib/Minify/JS/JShrink.php',
|
||||
'Minify\\Logger\\LegacyHandler' => $vendorDir . '/mrclay/minify/lib/Minify/Logger/LegacyHandler.php',
|
||||
'Minify_Build' => $vendorDir . '/mrclay/minify/lib/Minify/Build.php',
|
||||
'Minify_CSS' => $vendorDir . '/mrclay/minify/lib/Minify/CSS.php',
|
||||
'Minify_CSS_Compressor' => $vendorDir . '/mrclay/minify/lib/Minify/CSS/Compressor.php',
|
||||
'Minify_CSS_UriRewriter' => $vendorDir . '/mrclay/minify/lib/Minify/CSS/UriRewriter.php',
|
||||
'Minify_CSSmin' => $vendorDir . '/mrclay/minify/lib/Minify/CSSmin.php',
|
||||
'Minify_CacheInterface' => $vendorDir . '/mrclay/minify/lib/Minify/CacheInterface.php',
|
||||
'Minify_Cache_APC' => $vendorDir . '/mrclay/minify/lib/Minify/Cache/APC.php',
|
||||
'Minify_Cache_File' => $vendorDir . '/mrclay/minify/lib/Minify/Cache/File.php',
|
||||
'Minify_Cache_Memcache' => $vendorDir . '/mrclay/minify/lib/Minify/Cache/Memcache.php',
|
||||
'Minify_Cache_Null' => $vendorDir . '/mrclay/minify/lib/Minify/Cache/Null.php',
|
||||
'Minify_Cache_WinCache' => $vendorDir . '/mrclay/minify/lib/Minify/Cache/WinCache.php',
|
||||
'Minify_Cache_XCache' => $vendorDir . '/mrclay/minify/lib/Minify/Cache/XCache.php',
|
||||
'Minify_Cache_ZendPlatform' => $vendorDir . '/mrclay/minify/lib/Minify/Cache/ZendPlatform.php',
|
||||
'Minify_ClosureCompiler' => $vendorDir . '/mrclay/minify/lib/Minify/ClosureCompiler.php',
|
||||
'Minify_ClosureCompiler_Exception' => $vendorDir . '/mrclay/minify/lib/Minify/ClosureCompiler.php',
|
||||
'Minify_CommentPreserver' => $vendorDir . '/mrclay/minify/lib/Minify/CommentPreserver.php',
|
||||
'Minify_ControllerInterface' => $vendorDir . '/mrclay/minify/lib/Minify/ControllerInterface.php',
|
||||
'Minify_Controller_Base' => $vendorDir . '/mrclay/minify/lib/Minify/Controller/Base.php',
|
||||
'Minify_Controller_Files' => $vendorDir . '/mrclay/minify/lib/Minify/Controller/Files.php',
|
||||
'Minify_Controller_Groups' => $vendorDir . '/mrclay/minify/lib/Minify/Controller/Groups.php',
|
||||
'Minify_Controller_MinApp' => $vendorDir . '/mrclay/minify/lib/Minify/Controller/MinApp.php',
|
||||
'Minify_Controller_Page' => $vendorDir . '/mrclay/minify/lib/Minify/Controller/Page.php',
|
||||
'Minify_DebugDetector' => $vendorDir . '/mrclay/minify/lib/Minify/DebugDetector.php',
|
||||
'Minify_Env' => $vendorDir . '/mrclay/minify/lib/Minify/Env.php',
|
||||
'Minify_HTML' => $vendorDir . '/mrclay/minify/lib/Minify/HTML.php',
|
||||
'Minify_HTML_Helper' => $vendorDir . '/mrclay/minify/lib/Minify/HTML/Helper.php',
|
||||
'Minify_ImportProcessor' => $vendorDir . '/mrclay/minify/lib/Minify/ImportProcessor.php',
|
||||
'Minify_JS_ClosureCompiler' => $vendorDir . '/mrclay/minify/lib/Minify/JS/ClosureCompiler.php',
|
||||
'Minify_JS_ClosureCompiler_Exception' => $vendorDir . '/mrclay/minify/lib/Minify/JS/ClosureCompiler.php',
|
||||
'Minify_LessCssSource' => $vendorDir . '/mrclay/minify/lib/Minify/LessCssSource.php',
|
||||
'Minify_Lines' => $vendorDir . '/mrclay/minify/lib/Minify/Lines.php',
|
||||
'Minify_NailgunClosureCompiler' => $vendorDir . '/mrclay/minify/lib/Minify/NailgunClosureCompiler.php',
|
||||
'Minify_Packer' => $vendorDir . '/mrclay/minify/lib/Minify/Packer.php',
|
||||
'Minify_ScssCssSource' => $vendorDir . '/mrclay/minify/lib/Minify/ScssCssSource.php',
|
||||
'Minify_ServeConfiguration' => $vendorDir . '/mrclay/minify/lib/Minify/ServeConfiguration.php',
|
||||
'Minify_Source' => $vendorDir . '/mrclay/minify/lib/Minify/Source.php',
|
||||
'Minify_SourceInterface' => $vendorDir . '/mrclay/minify/lib/Minify/SourceInterface.php',
|
||||
'Minify_SourceSet' => $vendorDir . '/mrclay/minify/lib/Minify/SourceSet.php',
|
||||
'Minify_Source_Factory' => $vendorDir . '/mrclay/minify/lib/Minify/Source/Factory.php',
|
||||
'Minify_Source_FactoryException' => $vendorDir . '/mrclay/minify/lib/Minify/Source/FactoryException.php',
|
||||
'Minify_YUICompressor' => $vendorDir . '/mrclay/minify/lib/Minify/YUICompressor.php',
|
||||
'MrClay\\Cli' => $vendorDir . '/mrclay/minify/lib/MrClay/Cli.php',
|
||||
'MrClay\\Cli\\Arg' => $vendorDir . '/mrclay/minify/lib/MrClay/Cli/Arg.php',
|
||||
'lessc' => $vendorDir . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
'lessc_formatter_classic' => $vendorDir . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
'lessc_formatter_compressed' => $vendorDir . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
'lessc_formatter_lessjs' => $vendorDir . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
'lessc_parser' => $vendorDir . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
);
|
10
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_files.php
vendored
Normal file
10
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_files.php
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
// autoload_files.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'ce89ac35a6c330c55f4710717db9ff78' => $vendorDir . '/kriswallsmith/assetic/src/functions.php',
|
||||
);
|
14
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_namespaces.php
vendored
Normal file
14
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_namespaces.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Props\\' => array($vendorDir . '/mrclay/props-dic/src'),
|
||||
'Pimple' => array($vendorDir . '/pimple/pimple/src'),
|
||||
'JSMin\\' => array($vendorDir . '/mrclay/jsmin-php/src'),
|
||||
'ComponentInstaller' => array($vendorDir . '/robloach/component-installer/src'),
|
||||
'Assetic' => array($vendorDir . '/kriswallsmith/assetic/src'),
|
||||
);
|
22
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_psr4.php
vendored
Normal file
22
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_psr4.php
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'tubalmartin\\CssMin\\' => array($vendorDir . '/tubalmartin/cssmin/src'),
|
||||
'WebPConvert\\' => array($vendorDir . '/rosell-dk/webp-convert/src'),
|
||||
'WebPConvertCloudService\\' => array($vendorDir . '/rosell-dk/webp-convert-cloud-service/src'),
|
||||
'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
|
||||
'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
|
||||
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
|
||||
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
|
||||
'MatthiasMullie\\PathConverter\\' => array($vendorDir . '/matthiasmullie/path-converter/src'),
|
||||
'MatthiasMullie\\Minify\\' => array($vendorDir . '/matthiasmullie/minify/src'),
|
||||
'Intervention\\HttpAuth\\' => array($vendorDir . '/intervention/httpauth/src'),
|
||||
'ImageMimeTypeGuesser\\' => array($vendorDir . '/rosell-dk/image-mime-type-guesser/src'),
|
||||
'HtaccessCapabilityTester\\' => array($vendorDir . '/rosell-dk/htaccess-capability-tester/src'),
|
||||
'ExecWithFallback\\' => array($vendorDir . '/rosell-dk/exec-with-fallback/src'),
|
||||
);
|
73
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_real.php
vendored
Normal file
73
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_real.php
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitc3499d78139cb5a05b10193198da5145
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Composer\Autoload\ClassLoader
|
||||
*/
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitc3499d78139cb5a05b10193198da5145', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitc3499d78139cb5a05b10193198da5145', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitc3499d78139cb5a05b10193198da5145::getInitializer($loader));
|
||||
} else {
|
||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
}
|
||||
|
||||
$map = require __DIR__ . '/autoload_psr4.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->setPsr4($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
}
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInitc3499d78139cb5a05b10193198da5145::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequirec3499d78139cb5a05b10193198da5145($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequirec3499d78139cb5a05b10193198da5145($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
}
|
||||
}
|
212
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_static.php
vendored
Normal file
212
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/autoload_static.php
vendored
Normal file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
// autoload_static.php @generated by Composer
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitc3499d78139cb5a05b10193198da5145
|
||||
{
|
||||
public static $files = array (
|
||||
'ce89ac35a6c330c55f4710717db9ff78' => __DIR__ . '/..' . '/kriswallsmith/assetic/src/functions.php',
|
||||
);
|
||||
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
't' =>
|
||||
array (
|
||||
'tubalmartin\\CssMin\\' => 19,
|
||||
),
|
||||
'W' =>
|
||||
array (
|
||||
'WebPConvert\\' => 12,
|
||||
'WebPConvertCloudService\\' => 24,
|
||||
),
|
||||
'S' =>
|
||||
array (
|
||||
'Symfony\\Component\\Process\\' => 26,
|
||||
),
|
||||
'P' =>
|
||||
array (
|
||||
'Psr\\Log\\' => 8,
|
||||
'Psr\\Container\\' => 14,
|
||||
),
|
||||
'M' =>
|
||||
array (
|
||||
'Monolog\\' => 8,
|
||||
'MatthiasMullie\\PathConverter\\' => 29,
|
||||
'MatthiasMullie\\Minify\\' => 22,
|
||||
),
|
||||
'I' =>
|
||||
array (
|
||||
'Intervention\\HttpAuth\\' => 22,
|
||||
'ImageMimeTypeGuesser\\' => 21,
|
||||
),
|
||||
'H' =>
|
||||
array (
|
||||
'HtaccessCapabilityTester\\' => 25,
|
||||
),
|
||||
'E' =>
|
||||
array (
|
||||
'ExecWithFallback\\' => 17,
|
||||
),
|
||||
);
|
||||
|
||||
public static $prefixDirsPsr4 = array (
|
||||
'tubalmartin\\CssMin\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/tubalmartin/cssmin/src',
|
||||
),
|
||||
'WebPConvert\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/rosell-dk/webp-convert/src',
|
||||
),
|
||||
'WebPConvertCloudService\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/rosell-dk/webp-convert-cloud-service/src',
|
||||
),
|
||||
'Symfony\\Component\\Process\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/symfony/process',
|
||||
),
|
||||
'Psr\\Log\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/psr/log/Psr/Log',
|
||||
),
|
||||
'Psr\\Container\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/psr/container/src',
|
||||
),
|
||||
'Monolog\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/monolog/monolog/src/Monolog',
|
||||
),
|
||||
'MatthiasMullie\\PathConverter\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/matthiasmullie/path-converter/src',
|
||||
),
|
||||
'MatthiasMullie\\Minify\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/matthiasmullie/minify/src',
|
||||
),
|
||||
'Intervention\\HttpAuth\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/intervention/httpauth/src',
|
||||
),
|
||||
'ImageMimeTypeGuesser\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src',
|
||||
),
|
||||
'HtaccessCapabilityTester\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/rosell-dk/htaccess-capability-tester/src',
|
||||
),
|
||||
'ExecWithFallback\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src',
|
||||
),
|
||||
);
|
||||
|
||||
public static $prefixesPsr0 = array (
|
||||
'P' =>
|
||||
array (
|
||||
'Props\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/mrclay/props-dic/src',
|
||||
),
|
||||
'Pimple' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/pimple/pimple/src',
|
||||
),
|
||||
),
|
||||
'J' =>
|
||||
array (
|
||||
'JSMin\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/mrclay/jsmin-php/src',
|
||||
),
|
||||
),
|
||||
'C' =>
|
||||
array (
|
||||
'ComponentInstaller' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/robloach/component-installer/src',
|
||||
),
|
||||
),
|
||||
'A' =>
|
||||
array (
|
||||
'Assetic' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/kriswallsmith/assetic/src',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
public static $classMap = array (
|
||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||
'HTTP_ConditionalGet' => __DIR__ . '/..' . '/mrclay/minify/lib/HTTP/ConditionalGet.php',
|
||||
'HTTP_Encoder' => __DIR__ . '/..' . '/mrclay/minify/lib/HTTP/Encoder.php',
|
||||
'Minify' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify.php',
|
||||
'Minify\\App' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/App.php',
|
||||
'Minify\\Config' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Config.php',
|
||||
'Minify\\JS\\JShrink' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/JS/JShrink.php',
|
||||
'Minify\\Logger\\LegacyHandler' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Logger/LegacyHandler.php',
|
||||
'Minify_Build' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Build.php',
|
||||
'Minify_CSS' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/CSS.php',
|
||||
'Minify_CSS_Compressor' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/CSS/Compressor.php',
|
||||
'Minify_CSS_UriRewriter' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/CSS/UriRewriter.php',
|
||||
'Minify_CSSmin' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/CSSmin.php',
|
||||
'Minify_CacheInterface' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/CacheInterface.php',
|
||||
'Minify_Cache_APC' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Cache/APC.php',
|
||||
'Minify_Cache_File' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Cache/File.php',
|
||||
'Minify_Cache_Memcache' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Cache/Memcache.php',
|
||||
'Minify_Cache_Null' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Cache/Null.php',
|
||||
'Minify_Cache_WinCache' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Cache/WinCache.php',
|
||||
'Minify_Cache_XCache' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Cache/XCache.php',
|
||||
'Minify_Cache_ZendPlatform' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Cache/ZendPlatform.php',
|
||||
'Minify_ClosureCompiler' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/ClosureCompiler.php',
|
||||
'Minify_ClosureCompiler_Exception' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/ClosureCompiler.php',
|
||||
'Minify_CommentPreserver' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/CommentPreserver.php',
|
||||
'Minify_ControllerInterface' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/ControllerInterface.php',
|
||||
'Minify_Controller_Base' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Controller/Base.php',
|
||||
'Minify_Controller_Files' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Controller/Files.php',
|
||||
'Minify_Controller_Groups' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Controller/Groups.php',
|
||||
'Minify_Controller_MinApp' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Controller/MinApp.php',
|
||||
'Minify_Controller_Page' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Controller/Page.php',
|
||||
'Minify_DebugDetector' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/DebugDetector.php',
|
||||
'Minify_Env' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Env.php',
|
||||
'Minify_HTML' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/HTML.php',
|
||||
'Minify_HTML_Helper' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/HTML/Helper.php',
|
||||
'Minify_ImportProcessor' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/ImportProcessor.php',
|
||||
'Minify_JS_ClosureCompiler' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/JS/ClosureCompiler.php',
|
||||
'Minify_JS_ClosureCompiler_Exception' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/JS/ClosureCompiler.php',
|
||||
'Minify_LessCssSource' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/LessCssSource.php',
|
||||
'Minify_Lines' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Lines.php',
|
||||
'Minify_NailgunClosureCompiler' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/NailgunClosureCompiler.php',
|
||||
'Minify_Packer' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Packer.php',
|
||||
'Minify_ScssCssSource' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/ScssCssSource.php',
|
||||
'Minify_ServeConfiguration' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/ServeConfiguration.php',
|
||||
'Minify_Source' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Source.php',
|
||||
'Minify_SourceInterface' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/SourceInterface.php',
|
||||
'Minify_SourceSet' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/SourceSet.php',
|
||||
'Minify_Source_Factory' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Source/Factory.php',
|
||||
'Minify_Source_FactoryException' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/Source/FactoryException.php',
|
||||
'Minify_YUICompressor' => __DIR__ . '/..' . '/mrclay/minify/lib/Minify/YUICompressor.php',
|
||||
'MrClay\\Cli' => __DIR__ . '/..' . '/mrclay/minify/lib/MrClay/Cli.php',
|
||||
'MrClay\\Cli\\Arg' => __DIR__ . '/..' . '/mrclay/minify/lib/MrClay/Cli/Arg.php',
|
||||
'lessc' => __DIR__ . '/..' . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
'lessc_formatter_classic' => __DIR__ . '/..' . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
'lessc_formatter_compressed' => __DIR__ . '/..' . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
'lessc_formatter_lessjs' => __DIR__ . '/..' . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
'lessc_parser' => __DIR__ . '/..' . '/marcusschwarz/lesserphp/lessc.inc.php',
|
||||
);
|
||||
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitc3499d78139cb5a05b10193198da5145::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitc3499d78139cb5a05b10193198da5145::$prefixDirsPsr4;
|
||||
$loader->prefixesPsr0 = ComposerStaticInitc3499d78139cb5a05b10193198da5145::$prefixesPsr0;
|
||||
$loader->classMap = ComposerStaticInitc3499d78139cb5a05b10193198da5145::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
}
|
1505
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/installed.json
vendored
Normal file
1505
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/installed.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
238
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/installed.php
vendored
Normal file
238
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/composer/installed.php
vendored
Normal file
@ -0,0 +1,238 @@
|
||||
<?php return array(
|
||||
'root' => array(
|
||||
'pretty_version' => 'dev-master',
|
||||
'version' => 'dev-master',
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '557f38d8f383d158ab5b9e4a1b170c46768cecb4',
|
||||
'name' => 'updraftplus/wp-optimize',
|
||||
'dev' => false,
|
||||
),
|
||||
'versions' => array(
|
||||
'components/jquery' => array(
|
||||
'pretty_version' => '3.6.0',
|
||||
'version' => '3.6.0.0',
|
||||
'type' => 'component',
|
||||
'install_path' => __DIR__ . '/../components/jquery',
|
||||
'aliases' => array(),
|
||||
'reference' => '6cf38ee1fd04b6adf8e7dda161283aa35be818c3',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'components/jquery-blockui' => array(
|
||||
'pretty_version' => 'v2.71',
|
||||
'version' => '2.71.0.0',
|
||||
'type' => 'component',
|
||||
'install_path' => __DIR__ . '/../components/jquery-blockui',
|
||||
'aliases' => array(),
|
||||
'reference' => 'ba184b5d243e0be7183060f72ff58fabacc234d7',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'intervention/httpauth' => array(
|
||||
'pretty_version' => '3.0.3',
|
||||
'version' => '3.0.3.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../intervention/httpauth',
|
||||
'aliases' => array(),
|
||||
'reference' => '7742aa013e1a72f94379cb6623286f06fa1ea5f7',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'kriswallsmith/assetic' => array(
|
||||
'pretty_version' => 'v1.4.0',
|
||||
'version' => '1.4.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../kriswallsmith/assetic',
|
||||
'aliases' => array(),
|
||||
'reference' => 'e911c437dbdf006a8f62c2f59b15b2d69a5e0aa1',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'marcusschwarz/lesserphp' => array(
|
||||
'pretty_version' => 'v0.5.5',
|
||||
'version' => '0.5.5.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../marcusschwarz/lesserphp',
|
||||
'aliases' => array(),
|
||||
'reference' => '77ba82b5218ff228267d3b0e5ec8697be75e86a7',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'matthiasmullie/minify' => array(
|
||||
'pretty_version' => 'dev-master',
|
||||
'version' => 'dev-master',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../matthiasmullie/minify',
|
||||
'aliases' => array(
|
||||
0 => '9999999-dev',
|
||||
),
|
||||
'reference' => 'aa9c91d9f7d871b8f886e553da568e9b6768d01b',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'matthiasmullie/path-converter' => array(
|
||||
'pretty_version' => '1.1.3',
|
||||
'version' => '1.1.3.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../matthiasmullie/path-converter',
|
||||
'aliases' => array(),
|
||||
'reference' => 'e7d13b2c7e2f2268e1424aaed02085518afa02d9',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'monolog/monolog' => array(
|
||||
'pretty_version' => '2.3.5',
|
||||
'version' => '2.3.5.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../monolog/monolog',
|
||||
'aliases' => array(),
|
||||
'reference' => 'fd4380d6fc37626e2f799f29d91195040137eba9',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'mrclay/jsmin-php' => array(
|
||||
'pretty_version' => '2.4.0',
|
||||
'version' => '2.4.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../mrclay/jsmin-php',
|
||||
'aliases' => array(),
|
||||
'reference' => 'bb05febc9440852d39899255afd5569b7f21a72c',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'mrclay/minify' => array(
|
||||
'pretty_version' => '3.0.11',
|
||||
'version' => '3.0.11.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../mrclay/minify',
|
||||
'aliases' => array(),
|
||||
'reference' => 'f1572a580a8ab29c5c7df4319c4787c74f7dcb3e',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'mrclay/props-dic' => array(
|
||||
'pretty_version' => '3.0.0',
|
||||
'version' => '3.0.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../mrclay/props-dic',
|
||||
'aliases' => array(),
|
||||
'reference' => '0b0fd254e33e2d60bc2bcd7867f2ab3cdd05a843',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'pimple/pimple' => array(
|
||||
'pretty_version' => 'v3.5.0',
|
||||
'version' => '3.5.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../pimple/pimple',
|
||||
'aliases' => array(),
|
||||
'reference' => 'a94b3a4db7fb774b3d78dad2315ddc07629e1bed',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'psr/container' => array(
|
||||
'pretty_version' => '1.1.2',
|
||||
'version' => '1.1.2.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../psr/container',
|
||||
'aliases' => array(),
|
||||
'reference' => '513e0666f7216c7459170d56df27dfcefe1689ea',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'psr/log' => array(
|
||||
'pretty_version' => '1.1.4',
|
||||
'version' => '1.1.4.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../psr/log',
|
||||
'aliases' => array(),
|
||||
'reference' => 'd49695b909c3b7628b6289db5479a1c204601f11',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'psr/log-implementation' => array(
|
||||
'dev_requirement' => false,
|
||||
'provided' => array(
|
||||
0 => '1.0.0 || 2.0.0 || 3.0.0',
|
||||
),
|
||||
),
|
||||
'robloach/component-installer' => array(
|
||||
'pretty_version' => '0.0.12',
|
||||
'version' => '0.0.12.0',
|
||||
'type' => 'composer-installer',
|
||||
'install_path' => __DIR__ . '/../robloach/component-installer',
|
||||
'aliases' => array(),
|
||||
'reference' => '1864f25db21fc173e02a359f646acd596c1b0460',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'rosell-dk/exec-with-fallback' => array(
|
||||
'pretty_version' => '1.2.0',
|
||||
'version' => '1.2.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../rosell-dk/exec-with-fallback',
|
||||
'aliases' => array(),
|
||||
'reference' => 'f88a6b29abd0b580566056b7c1eb0434eb5db20d',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'rosell-dk/htaccess-capability-tester' => array(
|
||||
'pretty_version' => '1.0.0',
|
||||
'version' => '1.0.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../rosell-dk/htaccess-capability-tester',
|
||||
'aliases' => array(),
|
||||
'reference' => 'b4499dcd9fe8b538a617069fdf34ae3de877c977',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'rosell-dk/image-mime-type-guesser' => array(
|
||||
'pretty_version' => '0.4.0',
|
||||
'version' => '0.4.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../rosell-dk/image-mime-type-guesser',
|
||||
'aliases' => array(),
|
||||
'reference' => '5ff1c218faccb6ad7146b012e9544229271b30a9',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'rosell-dk/webp-convert' => array(
|
||||
'pretty_version' => '2.9.1',
|
||||
'version' => '2.9.1.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../rosell-dk/webp-convert',
|
||||
'aliases' => array(),
|
||||
'reference' => 'bb29cadb423691c620f395513e82fa414c17e464',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'rosell-dk/webp-convert-cloud-service' => array(
|
||||
'pretty_version' => '2.0.1',
|
||||
'version' => '2.0.1.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../rosell-dk/webp-convert-cloud-service',
|
||||
'aliases' => array(),
|
||||
'reference' => '703c2f1c76d30468ee3977170bfa3da138d8c4ad',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'symfony/process' => array(
|
||||
'pretty_version' => 'v3.4.47',
|
||||
'version' => '3.4.47.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../symfony/process',
|
||||
'aliases' => array(),
|
||||
'reference' => 'b8648cf1d5af12a44a51d07ef9bf980921f15fca',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'team-updraft/common-libs' => array(
|
||||
'pretty_version' => '3.0.2',
|
||||
'version' => '3.0.2.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../team-updraft/common-libs',
|
||||
'aliases' => array(),
|
||||
'reference' => '1551f78e0c3577aa993be9a2b7e7a7cca6a7fbca',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'tubalmartin/cssmin' => array(
|
||||
'pretty_version' => 'v4.1.1',
|
||||
'version' => '4.1.1.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../tubalmartin/cssmin',
|
||||
'aliases' => array(),
|
||||
'reference' => '3cbf557f4079d83a06f9c3ff9b957c022d7805cf',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'updraftplus/wp-optimize' => array(
|
||||
'pretty_version' => 'dev-master',
|
||||
'version' => 'dev-master',
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '557f38d8f383d158ab5b9e4a1b170c46768cecb4',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
);
|
9
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/LICENSE
vendored
Normal file
9
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/LICENSE
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Oliver Vogel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
236
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/AbstractVault.php
vendored
Normal file
236
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/AbstractVault.php
vendored
Normal file
@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth;
|
||||
|
||||
use Intervention\HttpAuth\Configurator\ArrayConfigurator;
|
||||
|
||||
abstract class AbstractVault
|
||||
{
|
||||
/**
|
||||
* Environment
|
||||
*
|
||||
* @var Environment
|
||||
*/
|
||||
protected $environment;
|
||||
|
||||
/**
|
||||
* Name of realm for vault
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $realm;
|
||||
|
||||
/**
|
||||
* Username for vault
|
||||
* @var string
|
||||
*/
|
||||
protected $username;
|
||||
|
||||
/**
|
||||
* Password for vault
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* Build directive for current vault
|
||||
*
|
||||
* @return Directive
|
||||
*/
|
||||
abstract public function getDirective(): Directive;
|
||||
|
||||
/**
|
||||
* Determine if vault is accessible by given key
|
||||
*
|
||||
* @param Key $key
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function unlocksWithKey(Key $key): bool;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
* @param mixed $realm
|
||||
* @param mixed $username
|
||||
* @param mixed $password
|
||||
*/
|
||||
public function __construct($realm, $username, $password)
|
||||
{
|
||||
$this->checkParameterValidity([
|
||||
'realm' => $realm,
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
$this->environment = new Environment();
|
||||
|
||||
$this->realm = $realm;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw exception if any of the given parameters are empty
|
||||
*
|
||||
* @param array $parameters
|
||||
* @return void
|
||||
*/
|
||||
private function checkParameterValidity(array $parameters): void
|
||||
{
|
||||
foreach ($parameters as $key => $value) {
|
||||
if (empty($value)) {
|
||||
throw new Exception\InvalidParameterException(
|
||||
'Cannot create HTTP authentication vault. Parameter "' . $key . '" cannot be empty.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return key from current token
|
||||
*
|
||||
* @return Key
|
||||
*/
|
||||
public function getKey(): Key
|
||||
{
|
||||
return $this->environment->getToken()->toKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Denies access for non-authenticated users
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function secure(): void
|
||||
{
|
||||
if (! $this->unlocksWithKey($this->getKey())) {
|
||||
$this->denyAccess();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name of realm
|
||||
*
|
||||
* @param string $realm
|
||||
* @return AbstractVault
|
||||
*/
|
||||
public function setRealm($realm): AbstractVault
|
||||
{
|
||||
$this->realm = $realm;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for setRealm()
|
||||
*
|
||||
* @param string $realm
|
||||
* @return AbstractVault
|
||||
*/
|
||||
public function realm($realm): AbstractVault
|
||||
{
|
||||
return $this->setRealm($realm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current realm name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRealm()
|
||||
{
|
||||
return $this->realm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set username for current vault
|
||||
*
|
||||
* @param string $username
|
||||
*/
|
||||
public function setUsername($username): AbstractVault
|
||||
{
|
||||
$this->username = $username;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for setUsername()
|
||||
*
|
||||
* @param string $username
|
||||
*/
|
||||
public function username($username): AbstractVault
|
||||
{
|
||||
return $this->setUsername($username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current username
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set password for current vault
|
||||
*
|
||||
* @param string $password
|
||||
* @return AbstractVault
|
||||
*/
|
||||
public function setPassword($password): AbstractVault
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for setPassword()
|
||||
*
|
||||
* @param string $password
|
||||
* @return AbstractVault
|
||||
*/
|
||||
public function password($password): AbstractVault
|
||||
{
|
||||
return $this->setPassword($password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current password
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set username and password at once
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return AbstractVault
|
||||
*/
|
||||
public function credentials($username, $password): AbstractVault
|
||||
{
|
||||
return $this->setUsername($username)->setPassword($password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends HTTP 401 Header
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function denyAccess(): void
|
||||
{
|
||||
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
|
||||
header($protocol . ' Unauthorized');
|
||||
header('WWW-Authenticate: ' . (string) $this->getDirective());
|
||||
exit('<strong>' . $protocol . ' 401 Unauthorized</strong>');
|
||||
}
|
||||
}
|
89
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/Directive.php
vendored
Normal file
89
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/Directive.php
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth;
|
||||
|
||||
class Directive
|
||||
{
|
||||
/**
|
||||
* Type of directive (basic|digest)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Array of parameters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters = [];
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function __construct($type, $parameters = [])
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format current instance
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format(): string
|
||||
{
|
||||
return sprintf(
|
||||
'%s %s',
|
||||
ucfirst(strtolower($this->type)),
|
||||
$this->getParametersString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return value of given key from all parameters, if existing
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParameter($key)
|
||||
{
|
||||
return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format current parameters as string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getParametersString(): string
|
||||
{
|
||||
return implode(', ', array_map(function ($key, $value) {
|
||||
return sprintf('%s="%s"', $key, $value);
|
||||
}, array_keys($this->parameters), $this->parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast object to string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->format();
|
||||
}
|
||||
}
|
55
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/Environment.php
vendored
Normal file
55
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/Environment.php
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth;
|
||||
|
||||
use Exception;
|
||||
|
||||
class Environment
|
||||
{
|
||||
/**
|
||||
* Available auth tokens
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tokenClassnames = [
|
||||
Token\PhpAuthUser::class,
|
||||
Token\HttpAuthentification::class,
|
||||
Token\RedirectHttpAuthorization::class,
|
||||
Token\PhpAuthDigest::class,
|
||||
Token\HttpAuthorization::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Get first active auth token from all available tokens
|
||||
*
|
||||
* @return TokenInterface
|
||||
*/
|
||||
public function getToken(): TokenInterface
|
||||
{
|
||||
foreach ($this->tokenClassnames as $classname) {
|
||||
if ($auth = $this->getActiveTokenOrNull($classname)) {
|
||||
return $auth;
|
||||
}
|
||||
}
|
||||
|
||||
return new Token\NullToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to parse auth token from given classname. Returns token object
|
||||
* if token is active and could be parsed or null.
|
||||
*
|
||||
* @param string $classname
|
||||
* @return TokenInterface|null
|
||||
*/
|
||||
private function getActiveTokenOrNull($classname)
|
||||
{
|
||||
try {
|
||||
$auth = new $classname();
|
||||
} catch (Exception $e) {
|
||||
$auth = null;
|
||||
}
|
||||
|
||||
return $auth;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class AuthentificationException extends RuntimeException
|
||||
{
|
||||
//
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class InvalidParameterException extends RuntimeException
|
||||
{
|
||||
//
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class NotSupportedException extends RuntimeException
|
||||
{
|
||||
//
|
||||
}
|
218
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/HttpAuth.php
vendored
Normal file
218
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/HttpAuth.php
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth;
|
||||
|
||||
class HttpAuth
|
||||
{
|
||||
/**
|
||||
* Authentication type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'basic';
|
||||
|
||||
/**
|
||||
* Name of authentication realm
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $realm = 'Secured Resource';
|
||||
|
||||
/**
|
||||
* Username
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $username = 'admin';
|
||||
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $password = 'secret';
|
||||
|
||||
/**
|
||||
* Static factory method
|
||||
*
|
||||
* @param array $config
|
||||
* @return HttpAuth
|
||||
*/
|
||||
public static function make(array $config = []): HttpAuth
|
||||
{
|
||||
return (new self())->configure($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure current instance by array
|
||||
*
|
||||
* @param array $config
|
||||
* @return HttpAuth
|
||||
*/
|
||||
private function configure(array $config = []): HttpAuth
|
||||
{
|
||||
foreach ($config as $key => $value) {
|
||||
if (isset(static::${$key})) {
|
||||
static::${$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create vault by current parameters and secure it
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function secure(): void
|
||||
{
|
||||
$this->getVault()->secure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create HTTP basic auth instance
|
||||
*
|
||||
* @return HttpAuth
|
||||
*/
|
||||
public function basic(): HttpAuth
|
||||
{
|
||||
static::$type = 'basic';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create HTTP digest auth instance
|
||||
*
|
||||
* @return HttpAuth
|
||||
*/
|
||||
public function digest(): HttpAuth
|
||||
{
|
||||
static::$type = 'digest';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type of configured vault
|
||||
*
|
||||
* @param string $value
|
||||
* @return HttpAuth
|
||||
*/
|
||||
public function type($value): HttpAuth
|
||||
{
|
||||
static::$type = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set realm name of configured vault
|
||||
*
|
||||
* @param string $value
|
||||
* @return HttpAuth
|
||||
*/
|
||||
public function realm($value): HttpAuth
|
||||
{
|
||||
static::$realm = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set username of configured vault
|
||||
*
|
||||
* @param string $value
|
||||
* @return HttpAuth
|
||||
*/
|
||||
public function username($value): HttpAuth
|
||||
{
|
||||
static::$username = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set password of configured vault
|
||||
*
|
||||
* @param string $value
|
||||
* @return HttpAuth
|
||||
*/
|
||||
public function password($value): HttpAuth
|
||||
{
|
||||
static::$password = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set credentials for configured vault
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return HttpAuth
|
||||
*/
|
||||
public function credentials($username, $password): HttpAuth
|
||||
{
|
||||
return $this->username($username)->password($password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type of current instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return static::$type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get realm of current instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRealm()
|
||||
{
|
||||
return static::$realm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get username of current instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return static::$username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get password of current instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return static::$password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return ready configured vault
|
||||
*
|
||||
* @return AbstractVault
|
||||
*/
|
||||
protected function getVault(): AbstractVault
|
||||
{
|
||||
$classname = sprintf('%s\Vault\%sVault', __NAMESPACE__, ucfirst(strtolower(static::$type)));
|
||||
|
||||
if (! class_exists($classname)) {
|
||||
throw new Exception\NotSupportedException(
|
||||
'Unable to create HTTP authentication vault of type "' . static::$type . '".'
|
||||
);
|
||||
}
|
||||
|
||||
return new $classname(static::$realm, static::$username, static::$password);
|
||||
}
|
||||
}
|
187
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/Key.php
vendored
Normal file
187
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/intervention/httpauth/src/Key.php
vendored
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth;
|
||||
|
||||
class Key
|
||||
{
|
||||
/**
|
||||
* Realm
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $realm;
|
||||
|
||||
/**
|
||||
* Username
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* QOP
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $qop;
|
||||
|
||||
/**
|
||||
* Nonce
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $nonce;
|
||||
|
||||
/**
|
||||
* Opaque
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $opaque;
|
||||
|
||||
/**
|
||||
* NC
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $nc;
|
||||
|
||||
/**
|
||||
* uri
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $uri;
|
||||
|
||||
/**
|
||||
* cnonce
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cnonce;
|
||||
|
||||
/**
|
||||
* Response
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $response;
|
||||
|
||||
public function getRealm()
|
||||
{
|
||||
return $this->realm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current username
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current password
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current qop
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQop()
|
||||
{
|
||||
return $this->qop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current nonce
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNonce()
|
||||
{
|
||||
return $this->nonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current opaque
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOpaque()
|
||||
{
|
||||
return $this->opaque;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current uri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current nc
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNc()
|
||||
{
|
||||
return $this->nc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current cnonce
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCnonce()
|
||||
{
|
||||
return $this->cnonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current response
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set property to given value on current instance
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Key
|
||||
*/
|
||||
public function setProperty($name, $value): Key
|
||||
{
|
||||
if (property_exists($this, $name)) {
|
||||
$this->{$name} = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Laravel\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class HttpAuth extends Facade
|
||||
{
|
||||
/**
|
||||
* Return facade accessor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'httpauth';
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Laravel;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Intervention\HttpAuth\HttpAuth;
|
||||
|
||||
class HttpAuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__ . '/../config/config.php' => config_path('httpauth.php')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// merge default config
|
||||
$this->mergeConfigFrom(
|
||||
__DIR__ . '/../config/config.php',
|
||||
'httpauth'
|
||||
);
|
||||
|
||||
// register singleton
|
||||
$this->app->singleton('httpauth', function ($app) {
|
||||
return HttpAuth::make($app['config']->get('httpauth'));
|
||||
});
|
||||
|
||||
// bind classname
|
||||
$this->app->bind('Intervention\HttpAuth\HttpAuth', function ($app) {
|
||||
return HttpAuth::make($app['config']->get('httpauth'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return ['httpauth'];
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Token;
|
||||
|
||||
use Intervention\HttpAuth\Key;
|
||||
|
||||
class HttpAuthentification extends NullToken
|
||||
{
|
||||
/**
|
||||
* Parsed authentification value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Transform current instance to key object
|
||||
*
|
||||
* @return Key
|
||||
*/
|
||||
public function toKey(): Key
|
||||
{
|
||||
list($username, $password) = explode(':', base64_decode(substr($this->value, 6)));
|
||||
|
||||
$key = new Key();
|
||||
$key->setProperty('username', $username);
|
||||
$key->setProperty('password', $password);
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse environment variables and store value in object
|
||||
*
|
||||
* @return bool "true" if value was found or "false"
|
||||
*/
|
||||
protected function parse(): bool
|
||||
{
|
||||
$value = $this->getArrayValue($_SERVER, 'HTTP_AUTHENTICATION');
|
||||
if (strtolower(substr($value, 0, 5)) === 'basic') {
|
||||
$this->value = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Token;
|
||||
|
||||
class HttpAuthorization extends PhpAuthDigest
|
||||
{
|
||||
/**
|
||||
* Parse environment variables and store value in object
|
||||
*
|
||||
* @return bool "true" if value was found or "false"
|
||||
*/
|
||||
protected function parse(): bool
|
||||
{
|
||||
$value = $this->getArrayValue($_SERVER, 'HTTP_AUTHORIZATION');
|
||||
if (strtolower(substr($value, 0, 6)) === 'digest') {
|
||||
$this->value = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Token;
|
||||
|
||||
use Intervention\HttpAuth\Exception\AuthentificationException;
|
||||
use Intervention\HttpAuth\Key;
|
||||
use Intervention\HttpAuth\TokenInterface;
|
||||
|
||||
class NullToken implements TokenInterface
|
||||
{
|
||||
/**
|
||||
* Create new instance
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ($this->parse() === false) {
|
||||
throw new AuthentificationException('Failed to parse token');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform current instance to key object
|
||||
*
|
||||
* @return Key
|
||||
*/
|
||||
public function toKey(): Key
|
||||
{
|
||||
return new Key();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse environment variables and store value in object
|
||||
*
|
||||
* @return bool "true" if value was found or "false"
|
||||
*/
|
||||
protected function parse(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of given key in given array data.
|
||||
* Returns null if key doesn't exists
|
||||
*
|
||||
* @param array $data
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getArrayValue($data, $key)
|
||||
{
|
||||
if (array_key_exists($key, $data)) {
|
||||
return $data[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Token;
|
||||
|
||||
use Intervention\HttpAuth\Key;
|
||||
|
||||
class PhpAuthDigest extends NullToken
|
||||
{
|
||||
/**
|
||||
* Parsed authentification value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Transform current instance to key object
|
||||
*
|
||||
* @return Key
|
||||
*/
|
||||
public function toKey(): Key
|
||||
{
|
||||
$authKey = new Key();
|
||||
preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $this->value, $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $m) {
|
||||
$key = $m[1];
|
||||
$value = $m[2] ? $m[2] : $m[3];
|
||||
$authKey->setProperty($key, $value);
|
||||
}
|
||||
|
||||
return $authKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse environment variables and store value in object
|
||||
*
|
||||
* @return bool "true" if value was found or "false"
|
||||
*/
|
||||
protected function parse(): bool
|
||||
{
|
||||
if ($value = $this->getArrayValue($_SERVER, 'PHP_AUTH_DIGEST')) {
|
||||
$this->value = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Token;
|
||||
|
||||
use Intervention\HttpAuth\Key;
|
||||
|
||||
class PhpAuthUser extends NullToken
|
||||
{
|
||||
/**
|
||||
* Parsed authentification username
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $username;
|
||||
|
||||
/**
|
||||
* Parsed authentification password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* Transform current instance to key object
|
||||
*
|
||||
* @return Key
|
||||
*/
|
||||
public function toKey(): Key
|
||||
{
|
||||
$key = new Key();
|
||||
$key->setProperty('username', $this->username);
|
||||
$key->setProperty('password', $this->password);
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse environment variables and store value in object
|
||||
*
|
||||
* @return bool "true" if value was found or "false"
|
||||
*/
|
||||
protected function parse(): bool
|
||||
{
|
||||
if ($username = $this->getArrayValue($_SERVER, 'PHP_AUTH_USER')) {
|
||||
$this->username = $username;
|
||||
$this->password = array_key_exists('PHP_AUTH_PW', $_SERVER) ? $_SERVER['PHP_AUTH_PW'] : null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Token;
|
||||
|
||||
class RedirectHttpAuthorization extends HttpAuthentification
|
||||
{
|
||||
/**
|
||||
* Parse environment variables and store value in object
|
||||
*
|
||||
* @return bool "true" if value was found or "false"
|
||||
*/
|
||||
protected function parse(): bool
|
||||
{
|
||||
$value = $this->getArrayValue($_SERVER, 'REDIRECT_HTTP_AUTHORIZATION');
|
||||
if (strtolower(substr($value, 0, 5)) === 'basic') {
|
||||
$this->value = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth;
|
||||
|
||||
interface TokenInterface
|
||||
{
|
||||
/**
|
||||
* Transform current instance to key object
|
||||
*
|
||||
* @return Key
|
||||
*/
|
||||
public function toKey(): Key;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Vault;
|
||||
|
||||
use Intervention\HttpAuth\AbstractVault;
|
||||
use Intervention\HttpAuth\Directive;
|
||||
use Intervention\HttpAuth\Key;
|
||||
|
||||
class BasicVault extends AbstractVault
|
||||
{
|
||||
/**
|
||||
* Determine if given key is able to unlock (access) vault.
|
||||
*
|
||||
* @param Key $key
|
||||
* @return bool
|
||||
*/
|
||||
public function unlocksWithKey(Key $key): bool
|
||||
{
|
||||
$username_match = $this->getUsername() == $key->getUsername();
|
||||
$password_match = $this->getPassword() == $key->getPassword();
|
||||
|
||||
return $username_match && $password_match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return auth directive
|
||||
*
|
||||
* @return Directive
|
||||
*/
|
||||
public function getDirective(): Directive
|
||||
{
|
||||
return new Directive('basic', [
|
||||
'realm' => $this->getRealm(),
|
||||
'charset' => 'UTF-8',
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\HttpAuth\Vault;
|
||||
|
||||
use Intervention\HttpAuth\AbstractVault;
|
||||
use Intervention\HttpAuth\Directive;
|
||||
use Intervention\HttpAuth\Key;
|
||||
|
||||
class DigestVault extends AbstractVault
|
||||
{
|
||||
/**
|
||||
* Determine if given key is able to unlock (access) vault.
|
||||
*
|
||||
* @param Key $key
|
||||
* @return bool
|
||||
*/
|
||||
public function unlocksWithKey(Key $key): bool
|
||||
{
|
||||
$username_match = $key->getUsername() == $this->getUsername();
|
||||
$hash_match = $key->getResponse() == $this->getKeyHash($key);
|
||||
|
||||
return $username_match && $hash_match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and return hash from given key/vault
|
||||
*
|
||||
* @param Key $key
|
||||
* @return string
|
||||
*/
|
||||
private function getKeyHash(Key $key): string
|
||||
{
|
||||
return md5(implode(':', [
|
||||
md5(sprintf('%s:%s:%s', $key->getUsername(), $this->getRealm(), $this->getPassword())),
|
||||
$key->getNonce(),
|
||||
$key->getNc(),
|
||||
$key->getCnonce(),
|
||||
$key->getQop(),
|
||||
md5(sprintf('%s:%s', $this->getRequestMethod(), $key->getUri())),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTTP request method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getRequestMethod()
|
||||
{
|
||||
return isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return auth directive
|
||||
*
|
||||
* @return Directive
|
||||
*/
|
||||
public function getDirective(): Directive
|
||||
{
|
||||
return new Directive('digest', [
|
||||
'realm' => $this->getRealm(),
|
||||
'qop' => 'auth',
|
||||
'nonce' => uniqid(),
|
||||
'opaque' => md5($this->getRealm()),
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication type
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Intervention HttpAuth supports "basic" and "digest" authentication
|
||||
| implementations. "Basic" is the simplest technique, while "Digest" applies
|
||||
| hash functions to the password before sending it over the network.
|
||||
|
|
||||
| Supported: "basic", "digest"
|
||||
|
|
||||
*/
|
||||
'type' => 'basic',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Name of secured resource. Clients must authentificate to each named realm.
|
||||
|
|
||||
*/
|
||||
'realm' => 'Secured',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication username
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Username to access the secured realm in combination with a password.
|
||||
|
|
||||
*/
|
||||
'username' => 'admin',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Password to access the secured realm in combination with the username.
|
||||
|
|
||||
*/
|
||||
'password' => '1234'
|
||||
|
||||
];
|
19
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/kriswallsmith/assetic/LICENSE
vendored
Normal file
19
hamrokhaanpaan/wp-content/__plugins/wp-optimize/vendor/kriswallsmith/assetic/LICENSE
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2010-2015 OpenSky Project Inc
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Cache\CacheInterface;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
use Assetic\Filter\HashableInterface;
|
||||
|
||||
/**
|
||||
* Caches an asset to avoid the cost of loading and dumping.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetCache implements AssetInterface
|
||||
{
|
||||
private $asset;
|
||||
private $cache;
|
||||
|
||||
public function __construct(AssetInterface $asset, CacheInterface $cache)
|
||||
{
|
||||
$this->asset = $asset;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
public function ensureFilter(FilterInterface $filter)
|
||||
{
|
||||
$this->asset->ensureFilter($filter);
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->asset->getFilters();
|
||||
}
|
||||
|
||||
public function clearFilters()
|
||||
{
|
||||
$this->asset->clearFilters();
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$cacheKey = self::getCacheKey($this->asset, $additionalFilter, 'load');
|
||||
if ($this->cache->has($cacheKey)) {
|
||||
$this->asset->setContent($this->cache->get($cacheKey));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->asset->load($additionalFilter);
|
||||
$this->cache->set($cacheKey, $this->asset->getContent());
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$cacheKey = self::getCacheKey($this->asset, $additionalFilter, 'dump');
|
||||
if ($this->cache->has($cacheKey)) {
|
||||
return $this->cache->get($cacheKey);
|
||||
}
|
||||
|
||||
$content = $this->asset->dump($additionalFilter);
|
||||
$this->cache->set($cacheKey, $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->asset->getContent();
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->asset->setContent($content);
|
||||
}
|
||||
|
||||
public function getSourceRoot()
|
||||
{
|
||||
return $this->asset->getSourceRoot();
|
||||
}
|
||||
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->asset->getSourcePath();
|
||||
}
|
||||
|
||||
public function getSourceDirectory()
|
||||
{
|
||||
return $this->asset->getSourceDirectory();
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->asset->getTargetPath();
|
||||
}
|
||||
|
||||
public function setTargetPath($targetPath)
|
||||
{
|
||||
$this->asset->setTargetPath($targetPath);
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
return $this->asset->getLastModified();
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return $this->asset->getVars();
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
$this->asset->setValues($values);
|
||||
}
|
||||
|
||||
public function getValues()
|
||||
{
|
||||
return $this->asset->getValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cache key for the current asset.
|
||||
*
|
||||
* The key is composed of everything but an asset's content:
|
||||
*
|
||||
* * source root
|
||||
* * source path
|
||||
* * target url
|
||||
* * last modified
|
||||
* * filters
|
||||
*
|
||||
* @param AssetInterface $asset The asset
|
||||
* @param FilterInterface $additionalFilter Any additional filter being applied
|
||||
* @param string $salt Salt for the key
|
||||
*
|
||||
* @return string A key for identifying the current asset
|
||||
*/
|
||||
private static function getCacheKey(AssetInterface $asset, FilterInterface $additionalFilter = null, $salt = '')
|
||||
{
|
||||
if ($additionalFilter) {
|
||||
$asset = clone $asset;
|
||||
$asset->ensureFilter($additionalFilter);
|
||||
}
|
||||
|
||||
$cacheKey = $asset->getSourceRoot();
|
||||
$cacheKey .= $asset->getSourcePath();
|
||||
$cacheKey .= $asset->getTargetPath();
|
||||
$cacheKey .= $asset->getLastModified();
|
||||
|
||||
foreach ($asset->getFilters() as $filter) {
|
||||
if ($filter instanceof HashableInterface) {
|
||||
$cacheKey .= $filter->hash();
|
||||
} else {
|
||||
$cacheKey .= serialize($filter);
|
||||
}
|
||||
}
|
||||
|
||||
if ($values = $asset->getValues()) {
|
||||
asort($values);
|
||||
$cacheKey .= serialize($values);
|
||||
}
|
||||
|
||||
return md5($cacheKey.$salt);
|
||||
}
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Asset\Iterator\AssetCollectionFilterIterator;
|
||||
use Assetic\Asset\Iterator\AssetCollectionIterator;
|
||||
use Assetic\Filter\FilterCollection;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* A collection of assets.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetCollection implements \IteratorAggregate, AssetCollectionInterface
|
||||
{
|
||||
private $assets;
|
||||
private $filters;
|
||||
private $sourceRoot;
|
||||
private $targetPath;
|
||||
private $content;
|
||||
private $clones;
|
||||
private $vars;
|
||||
private $values;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $assets Assets for the current collection
|
||||
* @param array $filters Filters for the current collection
|
||||
* @param string $sourceRoot The root directory
|
||||
* @param array $vars
|
||||
*/
|
||||
public function __construct($assets = array(), $filters = array(), $sourceRoot = null, array $vars = array())
|
||||
{
|
||||
$this->assets = array();
|
||||
foreach ($assets as $asset) {
|
||||
$this->add($asset);
|
||||
}
|
||||
|
||||
$this->filters = new FilterCollection($filters);
|
||||
$this->sourceRoot = $sourceRoot;
|
||||
$this->clones = new \SplObjectStorage();
|
||||
$this->vars = $vars;
|
||||
$this->values = array();
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->filters = clone $this->filters;
|
||||
$this->clones = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
return $this->assets;
|
||||
}
|
||||
|
||||
public function add(AssetInterface $asset)
|
||||
{
|
||||
$this->assets[] = $asset;
|
||||
}
|
||||
|
||||
public function removeLeaf(AssetInterface $needle, $graceful = false)
|
||||
{
|
||||
foreach ($this->assets as $i => $asset) {
|
||||
$clone = isset($this->clones[$asset]) ? $this->clones[$asset] : null;
|
||||
if (in_array($needle, array($asset, $clone), true)) {
|
||||
unset($this->clones[$asset], $this->assets[$i]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($asset instanceof AssetCollectionInterface && $asset->removeLeaf($needle, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($graceful) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Leaf not found.');
|
||||
}
|
||||
|
||||
public function replaceLeaf(AssetInterface $needle, AssetInterface $replacement, $graceful = false)
|
||||
{
|
||||
foreach ($this->assets as $i => $asset) {
|
||||
$clone = isset($this->clones[$asset]) ? $this->clones[$asset] : null;
|
||||
if (in_array($needle, array($asset, $clone), true)) {
|
||||
unset($this->clones[$asset]);
|
||||
$this->assets[$i] = $replacement;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($asset instanceof AssetCollectionInterface && $asset->replaceLeaf($needle, $replacement, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($graceful) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Leaf not found.');
|
||||
}
|
||||
|
||||
public function ensureFilter(FilterInterface $filter)
|
||||
{
|
||||
$this->filters->ensure($filter);
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filters->all();
|
||||
}
|
||||
|
||||
public function clearFilters()
|
||||
{
|
||||
$this->filters->clear();
|
||||
$this->clones = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
// loop through leaves and load each asset
|
||||
$parts = array();
|
||||
foreach ($this as $asset) {
|
||||
$asset->load($additionalFilter);
|
||||
$parts[] = $asset->getContent();
|
||||
}
|
||||
|
||||
$this->content = implode("\n", $parts);
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
// loop through leaves and dump each asset
|
||||
$parts = array();
|
||||
foreach ($this as $asset) {
|
||||
$parts[] = $asset->dump($additionalFilter);
|
||||
}
|
||||
|
||||
return implode("\n", $parts);
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function getSourceRoot()
|
||||
{
|
||||
return $this->sourceRoot;
|
||||
}
|
||||
|
||||
public function getSourcePath()
|
||||
{
|
||||
}
|
||||
|
||||
public function getSourceDirectory()
|
||||
{
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->targetPath;
|
||||
}
|
||||
|
||||
public function setTargetPath($targetPath)
|
||||
{
|
||||
$this->targetPath = $targetPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the highest last-modified value of all assets in the current collection.
|
||||
*
|
||||
* @return integer|null A UNIX timestamp
|
||||
*/
|
||||
public function getLastModified()
|
||||
{
|
||||
if (!count($this->assets)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mtime = 0;
|
||||
foreach ($this as $asset) {
|
||||
$assetMtime = $asset->getLastModified();
|
||||
if ($assetMtime > $mtime) {
|
||||
$mtime = $assetMtime;
|
||||
}
|
||||
}
|
||||
|
||||
return $mtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for looping recursively over unique leaves.
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new \RecursiveIteratorIterator(new AssetCollectionFilterIterator(new AssetCollectionIterator($this, $this->clones)));
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return $this->vars;
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
|
||||
foreach ($this as $asset) {
|
||||
$asset->setValues(array_intersect_key($values, array_flip($asset->getVars())));
|
||||
}
|
||||
}
|
||||
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
/**
|
||||
* An asset collection.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface AssetCollectionInterface extends AssetInterface, \Traversable
|
||||
{
|
||||
/**
|
||||
* Returns all child assets.
|
||||
*
|
||||
* @return array An array of AssetInterface objects
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Adds an asset to the current collection.
|
||||
*
|
||||
* @param AssetInterface $asset An asset
|
||||
*/
|
||||
public function add(AssetInterface $asset);
|
||||
|
||||
/**
|
||||
* Removes a leaf.
|
||||
*
|
||||
* @param AssetInterface $leaf The leaf to remove
|
||||
* @param Boolean $graceful Whether the failure should return false or throw an exception
|
||||
*
|
||||
* @return Boolean Whether the asset has been found
|
||||
*
|
||||
* @throws \InvalidArgumentException If the asset cannot be found
|
||||
*/
|
||||
public function removeLeaf(AssetInterface $leaf, $graceful = false);
|
||||
|
||||
/**
|
||||
* Replaces an existing leaf with a new one.
|
||||
*
|
||||
* @param AssetInterface $needle The current asset to replace
|
||||
* @param AssetInterface $replacement The new asset
|
||||
* @param Boolean $graceful Whether the failure should return false or throw an exception
|
||||
*
|
||||
* @return Boolean Whether the asset has been found
|
||||
*
|
||||
* @throws \InvalidArgumentException If the asset cannot be found
|
||||
*/
|
||||
public function replaceLeaf(AssetInterface $needle, AssetInterface $replacement, $graceful = false);
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* An asset has a mutable URL and content and can be loaded and dumped.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface AssetInterface
|
||||
{
|
||||
/**
|
||||
* Ensures the current asset includes the supplied filter.
|
||||
*
|
||||
* @param FilterInterface $filter A filter
|
||||
*/
|
||||
public function ensureFilter(FilterInterface $filter);
|
||||
|
||||
/**
|
||||
* Returns an array of filters currently applied.
|
||||
*
|
||||
* @return array An array of filters
|
||||
*/
|
||||
public function getFilters();
|
||||
|
||||
/**
|
||||
* Clears all filters from the current asset.
|
||||
*/
|
||||
public function clearFilters();
|
||||
|
||||
/**
|
||||
* Loads the asset into memory and applies load filters.
|
||||
*
|
||||
* You may provide an additional filter to apply during load.
|
||||
*
|
||||
* @param FilterInterface $additionalFilter An additional filter
|
||||
*/
|
||||
public function load(FilterInterface $additionalFilter = null);
|
||||
|
||||
/**
|
||||
* Applies dump filters and returns the asset as a string.
|
||||
*
|
||||
* You may provide an additional filter to apply during dump.
|
||||
*
|
||||
* Dumping an asset should not change its state.
|
||||
*
|
||||
* If the current asset has not been loaded yet, it should be
|
||||
* automatically loaded at this time.
|
||||
*
|
||||
* @param FilterInterface $additionalFilter An additional filter
|
||||
*
|
||||
* @return string The filtered content of the current asset
|
||||
*/
|
||||
public function dump(FilterInterface $additionalFilter = null);
|
||||
|
||||
/**
|
||||
* Returns the loaded content of the current asset.
|
||||
*
|
||||
* @return string The content
|
||||
*/
|
||||
public function getContent();
|
||||
|
||||
/**
|
||||
* Sets the content of the current asset.
|
||||
*
|
||||
* Filters can use this method to change the content of the asset.
|
||||
*
|
||||
* @param string $content The asset content
|
||||
*/
|
||||
public function setContent($content);
|
||||
|
||||
/**
|
||||
* Returns an absolute path or URL to the source asset's root directory.
|
||||
*
|
||||
* This value should be an absolute path to a directory in the filesystem,
|
||||
* an absolute URL with no path, or null.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* * '/path/to/web'
|
||||
* * 'http://example.com'
|
||||
* * null
|
||||
*
|
||||
* @return string|null The asset's root
|
||||
*/
|
||||
public function getSourceRoot();
|
||||
|
||||
/**
|
||||
* Returns the relative path for the source asset.
|
||||
*
|
||||
* This value can be combined with the asset's source root (if both are
|
||||
* non-null) to get something compatible with file_get_contents().
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* * 'js/main.js'
|
||||
* * 'main.js'
|
||||
* * null
|
||||
*
|
||||
* @return string|null The source asset path
|
||||
*/
|
||||
public function getSourcePath();
|
||||
|
||||
/**
|
||||
* Returns the asset's source directory.
|
||||
*
|
||||
* The source directory is the directory the asset was located in
|
||||
* and can be used to resolve references relative to an asset.
|
||||
*
|
||||
* @return string|null The asset's source directory
|
||||
*/
|
||||
public function getSourceDirectory();
|
||||
|
||||
/**
|
||||
* Returns the URL for the current asset.
|
||||
*
|
||||
* @return string|null A web URL where the asset will be dumped
|
||||
*/
|
||||
public function getTargetPath();
|
||||
|
||||
/**
|
||||
* Sets the URL for the current asset.
|
||||
*
|
||||
* @param string $targetPath A web URL where the asset will be dumped
|
||||
*/
|
||||
public function setTargetPath($targetPath);
|
||||
|
||||
/**
|
||||
* Returns the time the current asset was last modified.
|
||||
*
|
||||
* @return integer|null A UNIX timestamp
|
||||
*/
|
||||
public function getLastModified();
|
||||
|
||||
/**
|
||||
* Returns an array of variable names for this asset.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVars();
|
||||
|
||||
/**
|
||||
* Sets the values for the asset's variables.
|
||||
*
|
||||
* @param array $values
|
||||
*/
|
||||
public function setValues(array $values);
|
||||
|
||||
/**
|
||||
* Returns the current values for this asset.
|
||||
*
|
||||
* @return array an array of strings
|
||||
*/
|
||||
public function getValues();
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\AssetManager;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* A reference to an asset in the asset manager.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetReference implements AssetInterface
|
||||
{
|
||||
private $am;
|
||||
private $name;
|
||||
private $filters = array();
|
||||
private $clone = false;
|
||||
private $asset;
|
||||
|
||||
public function __construct(AssetManager $am, $name)
|
||||
{
|
||||
$this->am = $am;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->clone = true;
|
||||
|
||||
if ($this->asset) {
|
||||
$this->asset = clone $this->asset;
|
||||
}
|
||||
}
|
||||
|
||||
public function ensureFilter(FilterInterface $filter)
|
||||
{
|
||||
$this->filters[] = $filter;
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
$this->flushFilters();
|
||||
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function clearFilters()
|
||||
{
|
||||
$this->filters = array();
|
||||
$this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$this->flushFilters();
|
||||
|
||||
return $this->callAsset(__FUNCTION__, array($additionalFilter));
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$this->flushFilters();
|
||||
|
||||
return $this->callAsset(__FUNCTION__, array($additionalFilter));
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->callAsset(__FUNCTION__, array($content));
|
||||
}
|
||||
|
||||
public function getSourceRoot()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getSourceDirectory()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function setTargetPath($targetPath)
|
||||
{
|
||||
$this->callAsset(__FUNCTION__, array($targetPath));
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getValues()
|
||||
{
|
||||
return $this->callAsset(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
$this->callAsset(__FUNCTION__, array($values));
|
||||
}
|
||||
|
||||
// private
|
||||
|
||||
private function callAsset($method, $arguments = array())
|
||||
{
|
||||
$asset = $this->resolve();
|
||||
|
||||
return call_user_func_array(array($asset, $method), $arguments);
|
||||
}
|
||||
|
||||
private function flushFilters()
|
||||
{
|
||||
$asset = $this->resolve();
|
||||
|
||||
while ($filter = array_shift($this->filters)) {
|
||||
$asset->ensureFilter($filter);
|
||||
}
|
||||
}
|
||||
|
||||
private function resolve()
|
||||
{
|
||||
if ($this->asset) {
|
||||
return $this->asset;
|
||||
}
|
||||
|
||||
$asset = $this->am->get($this->name);
|
||||
|
||||
if ($this->clone) {
|
||||
$asset = $this->asset = clone $asset;
|
||||
}
|
||||
|
||||
return $asset;
|
||||
}
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterCollection;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* A base abstract asset.
|
||||
*
|
||||
* The methods load() and getLastModified() are left undefined, although a
|
||||
* reusable doLoad() method is available to child classes.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
abstract class BaseAsset implements AssetInterface
|
||||
{
|
||||
private $filters;
|
||||
private $sourceRoot;
|
||||
private $sourcePath;
|
||||
private $sourceDir;
|
||||
private $targetPath;
|
||||
private $content;
|
||||
private $loaded;
|
||||
private $vars;
|
||||
private $values;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $filters Filters for the asset
|
||||
* @param string $sourceRoot The root directory
|
||||
* @param string $sourcePath The asset path
|
||||
* @param array $vars
|
||||
*/
|
||||
public function __construct($filters = array(), $sourceRoot = null, $sourcePath = null, array $vars = array())
|
||||
{
|
||||
$this->filters = new FilterCollection($filters);
|
||||
$this->sourceRoot = $sourceRoot;
|
||||
$this->sourcePath = $sourcePath;
|
||||
if ($sourcePath && $sourceRoot) {
|
||||
$this->sourceDir = dirname("$sourceRoot/$sourcePath");
|
||||
}
|
||||
$this->vars = $vars;
|
||||
$this->values = array();
|
||||
$this->loaded = false;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->filters = clone $this->filters;
|
||||
}
|
||||
|
||||
public function ensureFilter(FilterInterface $filter)
|
||||
{
|
||||
$this->filters->ensure($filter);
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filters->all();
|
||||
}
|
||||
|
||||
public function clearFilters()
|
||||
{
|
||||
$this->filters->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encapsulates asset loading logic.
|
||||
*
|
||||
* @param string $content The asset content
|
||||
* @param FilterInterface $additionalFilter An additional filter
|
||||
*/
|
||||
protected function doLoad($content, FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$filter = clone $this->filters;
|
||||
if ($additionalFilter) {
|
||||
$filter->ensure($additionalFilter);
|
||||
}
|
||||
|
||||
$asset = clone $this;
|
||||
$asset->setContent($content);
|
||||
|
||||
$filter->filterLoad($asset);
|
||||
$this->content = $asset->getContent();
|
||||
|
||||
$this->loaded = true;
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
if (!$this->loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
$filter = clone $this->filters;
|
||||
if ($additionalFilter) {
|
||||
$filter->ensure($additionalFilter);
|
||||
}
|
||||
|
||||
$asset = clone $this;
|
||||
$filter->filterDump($asset);
|
||||
|
||||
return $asset->getContent();
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function getSourceRoot()
|
||||
{
|
||||
return $this->sourceRoot;
|
||||
}
|
||||
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->sourcePath;
|
||||
}
|
||||
|
||||
public function getSourceDirectory()
|
||||
{
|
||||
return $this->sourceDir;
|
||||
}
|
||||
|
||||
public function getTargetPath()
|
||||
{
|
||||
return $this->targetPath;
|
||||
}
|
||||
|
||||
public function setTargetPath($targetPath)
|
||||
{
|
||||
if ($this->vars) {
|
||||
foreach ($this->vars as $var) {
|
||||
if (false === strpos($targetPath, $var)) {
|
||||
throw new \RuntimeException(sprintf('The asset target path "%s" must contain the variable "{%s}".', $targetPath, $var));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->targetPath = $targetPath;
|
||||
}
|
||||
|
||||
public function getVars()
|
||||
{
|
||||
return $this->vars;
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
foreach ($values as $var => $v) {
|
||||
if (!in_array($var, $this->vars, true)) {
|
||||
throw new \InvalidArgumentException(sprintf('The asset with source path "%s" has no variable named "%s".', $this->sourcePath, $var));
|
||||
}
|
||||
}
|
||||
|
||||
$this->values = $values;
|
||||
$this->loaded = false;
|
||||
}
|
||||
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
use Assetic\Util\VarUtils;
|
||||
|
||||
/**
|
||||
* Represents an asset loaded from a file.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class FileAsset extends BaseAsset
|
||||
{
|
||||
private $source;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $source An absolute path
|
||||
* @param array $filters An array of filters
|
||||
* @param string $sourceRoot The source asset root directory
|
||||
* @param string $sourcePath The source asset path
|
||||
* @param array $vars
|
||||
*
|
||||
* @throws \InvalidArgumentException If the supplied root doesn't match the source when guessing the path
|
||||
*/
|
||||
public function __construct($source, $filters = array(), $sourceRoot = null, $sourcePath = null, array $vars = array())
|
||||
{
|
||||
if (null === $sourceRoot) {
|
||||
$sourceRoot = dirname($source);
|
||||
if (null === $sourcePath) {
|
||||
$sourcePath = basename($source);
|
||||
}
|
||||
} elseif (null === $sourcePath) {
|
||||
if (0 !== strpos($source, $sourceRoot)) {
|
||||
throw new \InvalidArgumentException(sprintf('The source "%s" is not in the root directory "%s"', $source, $sourceRoot));
|
||||
}
|
||||
|
||||
$sourcePath = substr($source, strlen($sourceRoot) + 1);
|
||||
}
|
||||
|
||||
$this->source = $source;
|
||||
|
||||
parent::__construct($filters, $sourceRoot, $sourcePath, $vars);
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$source = VarUtils::resolve($this->source, $this->getVars(), $this->getValues());
|
||||
|
||||
if (!is_file($source)) {
|
||||
throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
|
||||
}
|
||||
|
||||
$this->doLoad(file_get_contents($source), $additionalFilter);
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
$source = VarUtils::resolve($this->source, $this->getVars(), $this->getValues());
|
||||
|
||||
if (!is_file($source)) {
|
||||
throw new \RuntimeException(sprintf('The source file "%s" does not exist.', $source));
|
||||
}
|
||||
|
||||
return filemtime($source);
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
use Assetic\Util\VarUtils;
|
||||
|
||||
/**
|
||||
* A collection of assets loaded by glob.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class GlobAsset extends AssetCollection
|
||||
{
|
||||
private $globs;
|
||||
private $initialized;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|array $globs A single glob path or array of paths
|
||||
* @param array $filters An array of filters
|
||||
* @param string $root The root directory
|
||||
* @param array $vars
|
||||
*/
|
||||
public function __construct($globs, $filters = array(), $root = null, array $vars = array())
|
||||
{
|
||||
$this->globs = (array) $globs;
|
||||
$this->initialized = false;
|
||||
|
||||
parent::__construct(array(), $filters, $root, $vars);
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return parent::all();
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
parent::load($additionalFilter);
|
||||
}
|
||||
|
||||
public function dump(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return parent::dump($additionalFilter);
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return parent::getLastModified();
|
||||
}
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return parent::getIterator();
|
||||
}
|
||||
|
||||
public function setValues(array $values)
|
||||
{
|
||||
parent::setValues($values);
|
||||
$this->initialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the collection based on the glob(s) passed in.
|
||||
*/
|
||||
private function initialize()
|
||||
{
|
||||
foreach ($this->globs as $glob) {
|
||||
$glob = VarUtils::resolve($glob, $this->getVars(), $this->getValues());
|
||||
|
||||
if (false !== $paths = glob($glob)) {
|
||||
foreach ($paths as $path) {
|
||||
if (is_file($path)) {
|
||||
$asset = new FileAsset($path, array(), $this->getSourceRoot(), null, $this->getVars());
|
||||
$asset->setValues($this->getValues());
|
||||
$this->add($asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->initialized = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
use Assetic\Util\VarUtils;
|
||||
|
||||
/**
|
||||
* Represents an asset loaded via an HTTP request.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class HttpAsset extends BaseAsset
|
||||
{
|
||||
private $sourceUrl;
|
||||
private $ignoreErrors;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $sourceUrl The source URL
|
||||
* @param array $filters An array of filters
|
||||
* @param Boolean $ignoreErrors
|
||||
* @param array $vars
|
||||
*
|
||||
* @throws \InvalidArgumentException If the first argument is not an URL
|
||||
*/
|
||||
public function __construct($sourceUrl, $filters = array(), $ignoreErrors = false, array $vars = array())
|
||||
{
|
||||
if (0 === strpos($sourceUrl, '//')) {
|
||||
$sourceUrl = 'http:'.$sourceUrl;
|
||||
} elseif (false === strpos($sourceUrl, '://')) {
|
||||
throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL.', $sourceUrl));
|
||||
}
|
||||
|
||||
$this->sourceUrl = $sourceUrl;
|
||||
$this->ignoreErrors = $ignoreErrors;
|
||||
|
||||
list($scheme, $url) = explode('://', $sourceUrl, 2);
|
||||
list($host, $path) = explode('/', $url, 2);
|
||||
|
||||
parent::__construct($filters, $scheme.'://'.$host, $path, $vars);
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$content = @file_get_contents(
|
||||
VarUtils::resolve($this->sourceUrl, $this->getVars(), $this->getValues())
|
||||
);
|
||||
|
||||
if (false === $content && !$this->ignoreErrors) {
|
||||
throw new \RuntimeException(sprintf('Unable to load asset from URL "%s"', $this->sourceUrl));
|
||||
}
|
||||
|
||||
$this->doLoad($content, $additionalFilter);
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
if (false !== @file_get_contents($this->sourceUrl, false, stream_context_create(array('http' => array('method' => 'HEAD'))))) {
|
||||
foreach ($http_response_header as $header) {
|
||||
if (0 === stripos($header, 'Last-Modified: ')) {
|
||||
list(, $mtime) = explode(':', $header, 2);
|
||||
|
||||
return strtotime(trim($mtime));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset\Iterator;
|
||||
|
||||
/**
|
||||
* Asset collection filter iterator.
|
||||
*
|
||||
* The filter iterator is responsible for de-duplication of leaf assets based
|
||||
* on both strict equality and source URL.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetCollectionFilterIterator extends \RecursiveFilterIterator
|
||||
{
|
||||
private $visited;
|
||||
private $sources;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param AssetCollectionIterator $iterator The inner iterator
|
||||
* @param array $visited An array of visited asset objects
|
||||
* @param array $sources An array of visited source strings
|
||||
*/
|
||||
public function __construct(AssetCollectionIterator $iterator, array $visited = array(), array $sources = array())
|
||||
{
|
||||
parent::__construct($iterator);
|
||||
|
||||
$this->visited = $visited;
|
||||
$this->sources = $sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the current asset is a duplicate.
|
||||
*
|
||||
* De-duplication is performed based on either strict equality or by
|
||||
* matching sources.
|
||||
*
|
||||
* @return Boolean Returns true if we have not seen this asset yet
|
||||
*/
|
||||
public function accept()
|
||||
{
|
||||
$asset = $this->getInnerIterator()->current(true);
|
||||
$duplicate = false;
|
||||
|
||||
// check strict equality
|
||||
if (in_array($asset, $this->visited, true)) {
|
||||
$duplicate = true;
|
||||
} else {
|
||||
$this->visited[] = $asset;
|
||||
}
|
||||
|
||||
// check source
|
||||
$sourceRoot = $asset->getSourceRoot();
|
||||
$sourcePath = $asset->getSourcePath();
|
||||
if ($sourceRoot && $sourcePath) {
|
||||
$source = $sourceRoot.'/'.$sourcePath;
|
||||
if (in_array($source, $this->sources)) {
|
||||
$duplicate = true;
|
||||
} else {
|
||||
$this->sources[] = $source;
|
||||
}
|
||||
}
|
||||
|
||||
return !$duplicate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes visited objects and source URLs to the child iterator.
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return new self($this->getInnerIterator()->getChildren(), $this->visited, $this->sources);
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset\Iterator;
|
||||
|
||||
use Assetic\Asset\AssetCollectionInterface;
|
||||
|
||||
/**
|
||||
* Iterates over an asset collection.
|
||||
*
|
||||
* The iterator is responsible for cascading filters and target URL patterns
|
||||
* from parent to child assets.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetCollectionIterator implements \RecursiveIterator
|
||||
{
|
||||
private $assets;
|
||||
private $filters;
|
||||
private $vars;
|
||||
private $output;
|
||||
private $clones;
|
||||
|
||||
public function __construct(AssetCollectionInterface $coll, \SplObjectStorage $clones)
|
||||
{
|
||||
$this->assets = $coll->all();
|
||||
$this->filters = $coll->getFilters();
|
||||
$this->vars = $coll->getVars();
|
||||
$this->output = $coll->getTargetPath();
|
||||
$this->clones = $clones;
|
||||
|
||||
if (false === $pos = strrpos($this->output, '.')) {
|
||||
$this->output .= '_*';
|
||||
} else {
|
||||
$this->output = substr($this->output, 0, $pos).'_*'.substr($this->output, $pos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the current asset with filters and a target URL applied.
|
||||
*
|
||||
* @param Boolean $raw Returns the unmodified asset if true
|
||||
*
|
||||
* @return \Assetic\Asset\AssetInterface
|
||||
*/
|
||||
public function current($raw = false)
|
||||
{
|
||||
$asset = current($this->assets);
|
||||
|
||||
if ($raw) {
|
||||
return $asset;
|
||||
}
|
||||
|
||||
// clone once
|
||||
if (!isset($this->clones[$asset])) {
|
||||
$clone = $this->clones[$asset] = clone $asset;
|
||||
|
||||
// generate a target path based on asset name
|
||||
$name = sprintf('%s_%d', pathinfo($asset->getSourcePath(), PATHINFO_FILENAME) ?: 'part', $this->key() + 1);
|
||||
|
||||
$name = $this->removeDuplicateVar($name);
|
||||
|
||||
$clone->setTargetPath(str_replace('*', $name, $this->output));
|
||||
} else {
|
||||
$clone = $this->clones[$asset];
|
||||
}
|
||||
|
||||
// cascade filters
|
||||
foreach ($this->filters as $filter) {
|
||||
$clone->ensureFilter($filter);
|
||||
}
|
||||
|
||||
return $clone;
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->assets);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
return next($this->assets);
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
return reset($this->assets);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return false !== current($this->assets);
|
||||
}
|
||||
|
||||
public function hasChildren()
|
||||
{
|
||||
return current($this->assets) instanceof AssetCollectionInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses current()
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return new self($this->current(), $this->clones);
|
||||
}
|
||||
|
||||
private function removeDuplicateVar($name)
|
||||
{
|
||||
foreach ($this->vars as $var) {
|
||||
$var = '{'.$var.'}';
|
||||
if (false !== strpos($name, $var) && false !== strpos($this->output, $var)) {
|
||||
$name = str_replace($var, '', $name);
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Asset;
|
||||
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* Represents a string asset.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class StringAsset extends BaseAsset
|
||||
{
|
||||
private $string;
|
||||
private $lastModified;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $content The content of the asset
|
||||
* @param array $filters Filters for the asset
|
||||
* @param string $sourceRoot The source asset root directory
|
||||
* @param string $sourcePath The source asset path
|
||||
*/
|
||||
public function __construct($content, $filters = array(), $sourceRoot = null, $sourcePath = null)
|
||||
{
|
||||
$this->string = $content;
|
||||
|
||||
parent::__construct($filters, $sourceRoot, $sourcePath);
|
||||
}
|
||||
|
||||
public function load(FilterInterface $additionalFilter = null)
|
||||
{
|
||||
$this->doLoad($this->string, $additionalFilter);
|
||||
}
|
||||
|
||||
public function setLastModified($lastModified)
|
||||
{
|
||||
$this->lastModified = $lastModified;
|
||||
}
|
||||
|
||||
public function getLastModified()
|
||||
{
|
||||
return $this->lastModified;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
|
||||
/**
|
||||
* Manages assets.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetManager
|
||||
{
|
||||
private $assets = array();
|
||||
|
||||
/**
|
||||
* Gets an asset by name.
|
||||
*
|
||||
* @param string $name The asset name
|
||||
*
|
||||
* @return AssetInterface The asset
|
||||
*
|
||||
* @throws \InvalidArgumentException If there is no asset by that name
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (!isset($this->assets[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('There is no "%s" asset.', $name));
|
||||
}
|
||||
|
||||
return $this->assets[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current asset manager has a certain asset.
|
||||
*
|
||||
* @param string $name an asset name
|
||||
*
|
||||
* @return Boolean True if the asset has been set, false if not
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
return isset($this->assets[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an asset to the current asset manager.
|
||||
*
|
||||
* @param string $name The asset name
|
||||
* @param AssetInterface $asset The asset
|
||||
*
|
||||
* @throws \InvalidArgumentException If the asset name is invalid
|
||||
*/
|
||||
public function set($name, AssetInterface $asset)
|
||||
{
|
||||
if (!ctype_alnum(str_replace('_', '', $name))) {
|
||||
throw new \InvalidArgumentException(sprintf('The name "%s" is invalid.', $name));
|
||||
}
|
||||
|
||||
$this->assets[$name] = $asset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of asset names.
|
||||
*
|
||||
* @return array An array of asset names
|
||||
*/
|
||||
public function getNames()
|
||||
{
|
||||
return array_keys($this->assets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all assets.
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->assets = array();
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Util\VarUtils;
|
||||
|
||||
/**
|
||||
* Writes assets to the filesystem.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class AssetWriter
|
||||
{
|
||||
private $dir;
|
||||
private $values;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $dir The base web directory
|
||||
* @param array $values Variable values
|
||||
*
|
||||
* @throws \InvalidArgumentException if a variable value is not a string
|
||||
*/
|
||||
public function __construct($dir, array $values = array())
|
||||
{
|
||||
foreach ($values as $var => $vals) {
|
||||
foreach ($vals as $value) {
|
||||
if (!is_string($value)) {
|
||||
throw new \InvalidArgumentException(sprintf('All variable values must be strings, but got %s for variable "%s".', json_encode($value), $var));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->dir = $dir;
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
public function writeManagerAssets(AssetManager $am)
|
||||
{
|
||||
foreach ($am->getNames() as $name) {
|
||||
$this->writeAsset($am->get($name));
|
||||
}
|
||||
}
|
||||
|
||||
public function writeAsset(AssetInterface $asset)
|
||||
{
|
||||
foreach (VarUtils::getCombinations($asset->getVars(), $this->values) as $combination) {
|
||||
$asset->setValues($combination);
|
||||
|
||||
static::write(
|
||||
$this->dir.'/'.VarUtils::resolve(
|
||||
$asset->getTargetPath(),
|
||||
$asset->getVars(),
|
||||
$asset->getValues()
|
||||
),
|
||||
$asset->dump()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function write($path, $contents)
|
||||
{
|
||||
if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {
|
||||
throw new \RuntimeException('Unable to create directory '.$dir);
|
||||
}
|
||||
|
||||
if (false === @file_put_contents($path, $contents)) {
|
||||
throw new \RuntimeException('Unable to write file '.$path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not used.
|
||||
*
|
||||
* This method is provided for backward compatibility with certain versions
|
||||
* of AsseticBundle.
|
||||
*/
|
||||
private function getCombinations(array $vars)
|
||||
{
|
||||
return VarUtils::getCombinations($vars, $this->values);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Cache;
|
||||
|
||||
/**
|
||||
* Uses APC to cache files
|
||||
*
|
||||
* @author André Roaldseth <andre@roaldseth.net>
|
||||
*/
|
||||
class ApcCache implements CacheInterface
|
||||
{
|
||||
public $ttl = 0;
|
||||
|
||||
/**
|
||||
* @see CacheInterface::has()
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return apc_exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CacheInterface::get()
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = apc_fetch($key, $success);
|
||||
|
||||
if (!$success) {
|
||||
throw new \RuntimeException('There is no cached value for '.$key);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CacheInterface::set()
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$store = apc_store($key, $value, $this->ttl);
|
||||
|
||||
if (!$store) {
|
||||
throw new \RuntimeException('Unable to store "'.$key.'" for '.$this->ttl.' seconds.');
|
||||
}
|
||||
|
||||
return $store;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CacheInterface::remove()
|
||||
*/
|
||||
public function remove($key)
|
||||
{
|
||||
return apc_delete($key);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Cache;
|
||||
|
||||
/**
|
||||
* A simple array cache
|
||||
*
|
||||
* @author Michael Mifsud <xzyfer@gmail.com>
|
||||
*/
|
||||
class ArrayCache implements CacheInterface
|
||||
{
|
||||
private $cache = array();
|
||||
|
||||
/**
|
||||
* @see CacheInterface::has()
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return isset($this->cache[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CacheInterface::get()
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (!$this->has($key)) {
|
||||
throw new \RuntimeException('There is no cached value for '.$key);
|
||||
}
|
||||
|
||||
return $this->cache[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CacheInterface::set()
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->cache[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CacheInterface::remove()
|
||||
*/
|
||||
public function remove($key)
|
||||
{
|
||||
unset($this->cache[$key]);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Cache;
|
||||
|
||||
/**
|
||||
* Interface for a cache backend.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface CacheInterface
|
||||
{
|
||||
/**
|
||||
* Checks if the cache has a value for a key.
|
||||
*
|
||||
* @param string $key A unique key
|
||||
*
|
||||
* @return Boolean Whether the cache has a value for this key
|
||||
*/
|
||||
public function has($key);
|
||||
|
||||
/**
|
||||
* Returns the value for a key.
|
||||
*
|
||||
* @param string $key A unique key
|
||||
*
|
||||
* @return string|null The value in the cache
|
||||
*/
|
||||
public function get($key);
|
||||
|
||||
/**
|
||||
* Sets a value in the cache.
|
||||
*
|
||||
* @param string $key A unique key
|
||||
* @param string $value The value to cache
|
||||
*/
|
||||
public function set($key, $value);
|
||||
|
||||
/**
|
||||
* Removes a value from the cache.
|
||||
*
|
||||
* @param string $key A unique key
|
||||
*/
|
||||
public function remove($key);
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Cache;
|
||||
|
||||
/**
|
||||
* A config cache stores values using var_export() and include.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class ConfigCache
|
||||
{
|
||||
private $dir;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param string $dir The cache directory
|
||||
*/
|
||||
public function __construct($dir)
|
||||
{
|
||||
$this->dir = $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks of the cache has a file.
|
||||
*
|
||||
* @param string $resource A cache key
|
||||
*
|
||||
* @return Boolean True if a file exists
|
||||
*/
|
||||
public function has($resource)
|
||||
{
|
||||
return file_exists($this->getSourcePath($resource));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a value to a file.
|
||||
*
|
||||
* @param string $resource A cache key
|
||||
* @param mixed $value A value to cache
|
||||
*/
|
||||
public function set($resource, $value)
|
||||
{
|
||||
$path = $this->getSourcePath($resource);
|
||||
|
||||
if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new \RuntimeException('Unable to create directory '.$dir);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
if (false === @file_put_contents($path, sprintf("<?php\n\n// $resource\nreturn %s;\n", var_export($value, true)))) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new \RuntimeException('Unable to write file '.$path);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and returns the value for the supplied cache key.
|
||||
*
|
||||
* @param string $resource A cache key
|
||||
*
|
||||
* @return mixed The cached value
|
||||
*/
|
||||
public function get($resource)
|
||||
{
|
||||
$path = $this->getSourcePath($resource);
|
||||
|
||||
if (!file_exists($path)) {
|
||||
throw new \RuntimeException('There is no cached value for '.$resource);
|
||||
}
|
||||
|
||||
return include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a timestamp for when the cache was created.
|
||||
*
|
||||
* @param string $resource A cache key
|
||||
*
|
||||
* @return integer A UNIX timestamp
|
||||
*/
|
||||
public function getTimestamp($resource)
|
||||
{
|
||||
$path = $this->getSourcePath($resource);
|
||||
|
||||
if (!file_exists($path)) {
|
||||
throw new \RuntimeException('There is no cached value for '.$resource);
|
||||
}
|
||||
|
||||
if (false === $mtime = @filemtime($path)) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new \RuntimeException('Unable to determine file mtime for '.$path);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $mtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path where the file corresponding to the supplied cache key can be included from.
|
||||
*
|
||||
* @param string $resource A cache key
|
||||
*
|
||||
* @return string A file path
|
||||
*/
|
||||
private function getSourcePath($resource)
|
||||
{
|
||||
$key = md5($resource);
|
||||
|
||||
return $this->dir.'/'.$key[0].'/'.$key.'.php';
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Cache;
|
||||
|
||||
/**
|
||||
* Adds expiration to a cache backend.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class ExpiringCache implements CacheInterface
|
||||
{
|
||||
private $cache;
|
||||
private $lifetime;
|
||||
|
||||
public function __construct(CacheInterface $cache, $lifetime)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->lifetime = $lifetime;
|
||||
}
|
||||
|
||||
public function has($key)
|
||||
{
|
||||
if ($this->cache->has($key)) {
|
||||
if (time() < $this->cache->get($key.'.expires')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->cache->remove($key.'.expires');
|
||||
$this->cache->remove($key);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
return $this->cache->get($key);
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->cache->set($key.'.expires', time() + $this->lifetime);
|
||||
$this->cache->set($key, $value);
|
||||
}
|
||||
|
||||
public function remove($key)
|
||||
{
|
||||
$this->cache->remove($key.'.expires');
|
||||
$this->cache->remove($key);
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Cache;
|
||||
|
||||
/**
|
||||
* A simple filesystem cache.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class FilesystemCache implements CacheInterface
|
||||
{
|
||||
private $dir;
|
||||
|
||||
public function __construct($dir)
|
||||
{
|
||||
$this->dir = $dir;
|
||||
}
|
||||
|
||||
public function has($key)
|
||||
{
|
||||
return file_exists($this->dir.'/'.$key);
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
$path = $this->dir.'/'.$key;
|
||||
|
||||
if (!file_exists($path)) {
|
||||
throw new \RuntimeException('There is no cached value for '.$key);
|
||||
}
|
||||
|
||||
return file_get_contents($path);
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
if (!is_dir($this->dir) && false === @mkdir($this->dir, 0777, true)) {
|
||||
throw new \RuntimeException('Unable to create directory '.$this->dir);
|
||||
}
|
||||
|
||||
$path = $this->dir.'/'.$key;
|
||||
|
||||
if (false === @file_put_contents($path, $value)) {
|
||||
throw new \RuntimeException('Unable to write file '.$path);
|
||||
}
|
||||
}
|
||||
|
||||
public function remove($key)
|
||||
{
|
||||
$path = $this->dir.'/'.$key;
|
||||
|
||||
if (file_exists($path) && false === @unlink($path)) {
|
||||
throw new \RuntimeException('Unable to remove file '.$path);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Exception;
|
||||
|
||||
/**
|
||||
* Marker.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
interface Exception
|
||||
{
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Exception;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Describes an exception that occurred within a filter.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class FilterException extends \RuntimeException implements Exception
|
||||
{
|
||||
private $originalMessage;
|
||||
private $input;
|
||||
|
||||
public static function fromProcess(Process $proc)
|
||||
{
|
||||
$message = sprintf("An error occurred while running:\n%s", $proc->getCommandLine());
|
||||
|
||||
$errorOutput = $proc->getErrorOutput();
|
||||
if (!empty($errorOutput)) {
|
||||
$message .= "\n\nError Output:\n".str_replace("\r", '', $errorOutput);
|
||||
}
|
||||
|
||||
$output = $proc->getOutput();
|
||||
if (!empty($output)) {
|
||||
$message .= "\n\nOutput:\n".str_replace("\r", '', $output);
|
||||
}
|
||||
|
||||
return new self($message);
|
||||
}
|
||||
|
||||
public function __construct($message, $code = 0, \Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
|
||||
$this->originalMessage = $message;
|
||||
}
|
||||
|
||||
public function setInput($input)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->updateMessage();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInput()
|
||||
{
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
private function updateMessage()
|
||||
{
|
||||
$message = $this->originalMessage;
|
||||
|
||||
if (!empty($this->input)) {
|
||||
$message .= "\n\nInput:\n".$this->input;
|
||||
}
|
||||
|
||||
$this->message = $message;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
use Assetic\Factory\AssetFactory;
|
||||
use Assetic\ValueSupplierInterface;
|
||||
|
||||
class AsseticExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
|
||||
{
|
||||
protected $factory;
|
||||
protected $functions;
|
||||
protected $valueSupplier;
|
||||
|
||||
public function __construct(AssetFactory $factory, $functions = array(), ValueSupplierInterface $valueSupplier = null)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
$this->functions = array();
|
||||
$this->valueSupplier = $valueSupplier;
|
||||
|
||||
foreach ($functions as $function => $options) {
|
||||
if (is_integer($function) && is_string($options)) {
|
||||
$this->functions[$options] = array('filter' => $options);
|
||||
} else {
|
||||
$this->functions[$function] = $options + array('filter' => $function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTokenParsers()
|
||||
{
|
||||
return array(
|
||||
new AsseticTokenParser($this->factory, 'javascripts', 'js/*.js'),
|
||||
new AsseticTokenParser($this->factory, 'stylesheets', 'css/*.css'),
|
||||
new AsseticTokenParser($this->factory, 'image', 'images/*', true),
|
||||
);
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
$functions = array();
|
||||
foreach ($this->functions as $function => $filter) {
|
||||
$functions[] = new AsseticFilterFunction($function);
|
||||
}
|
||||
|
||||
return $functions;
|
||||
}
|
||||
|
||||
public function getGlobals()
|
||||
{
|
||||
return array(
|
||||
'assetic' => array(
|
||||
'debug' => $this->factory->isDebug(),
|
||||
'vars' => null !== $this->valueSupplier ? new ValueContainer($this->valueSupplier) : array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function getFilterInvoker($function)
|
||||
{
|
||||
return new AsseticFilterInvoker($this->factory, $this->functions[$function]);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'assetic';
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
class AsseticFilterFunction extends \Twig_SimpleFunction
|
||||
{
|
||||
public function __construct($name, $options = array())
|
||||
{
|
||||
parent::__construct($name, null, array_merge($options, array(
|
||||
'needs_environment' => false,
|
||||
'needs_context' => false,
|
||||
'node_class' => '\Assetic\Extension\Twig\AsseticFilterNode',
|
||||
)));
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
/**
|
||||
* Filters a single asset.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AsseticFilterInvoker
|
||||
{
|
||||
private $factory;
|
||||
private $filters;
|
||||
private $options;
|
||||
|
||||
public function __construct($factory, $filter)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
|
||||
if (is_array($filter) && isset($filter['filter'])) {
|
||||
$this->filters = (array) $filter['filter'];
|
||||
$this->options = isset($filter['options']) ? (array) $filter['options'] : array();
|
||||
} else {
|
||||
$this->filters = (array) $filter;
|
||||
$this->options = array();
|
||||
}
|
||||
}
|
||||
|
||||
public function getFactory()
|
||||
{
|
||||
return $this->factory;
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function invoke($input, array $options = array())
|
||||
{
|
||||
$asset = $this->factory->createAsset($input, $this->filters, $options + $this->options);
|
||||
|
||||
return $asset->getTargetPath();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
class AsseticFilterNode extends \Twig_Node_Expression_Function
|
||||
{
|
||||
protected function compileCallable(\Twig_Compiler $compiler)
|
||||
{
|
||||
$compiler->raw(sprintf('$this->env->getExtension(\'Assetic\\Extension\\Twig\\AsseticExtension\')->getFilterInvoker(\'%s\')->invoke', $this->getAttribute('name')));
|
||||
|
||||
$this->compileArguments($compiler);
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
|
||||
class AsseticNode extends \Twig_Node
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Available attributes:
|
||||
*
|
||||
* * debug: The debug mode
|
||||
* * combine: Whether to combine assets
|
||||
* * var_name: The name of the variable to expose to the body node
|
||||
*
|
||||
* @param AssetInterface $asset The asset
|
||||
* @param \Twig_Node $body The body node
|
||||
* @param array $inputs An array of input strings
|
||||
* @param array $filters An array of filter strings
|
||||
* @param string $name The name of the asset
|
||||
* @param array $attributes An array of attributes
|
||||
* @param integer $lineno The line number
|
||||
* @param string $tag The tag name
|
||||
*/
|
||||
public function __construct(AssetInterface $asset, \Twig_Node $body, array $inputs, array $filters, $name, array $attributes = array(), $lineno = 0, $tag = null)
|
||||
{
|
||||
$nodes = array('body' => $body);
|
||||
|
||||
$attributes = array_replace(
|
||||
array('debug' => null, 'combine' => null, 'var_name' => 'asset_url'),
|
||||
$attributes,
|
||||
array('asset' => $asset, 'inputs' => $inputs, 'filters' => $filters, 'name' => $name)
|
||||
);
|
||||
|
||||
parent::__construct($nodes, $attributes, $lineno, $tag);
|
||||
}
|
||||
|
||||
public function compile(\Twig_Compiler $compiler)
|
||||
{
|
||||
$compiler->addDebugInfo($this);
|
||||
|
||||
$combine = $this->getAttribute('combine');
|
||||
$debug = $this->getAttribute('debug');
|
||||
|
||||
if (null === $combine && null !== $debug) {
|
||||
$combine = !$debug;
|
||||
}
|
||||
|
||||
if (null === $combine) {
|
||||
$compiler
|
||||
->write("if (isset(\$context['assetic']['debug']) && \$context['assetic']['debug']) {\n")
|
||||
->indent()
|
||||
;
|
||||
|
||||
$this->compileDebug($compiler);
|
||||
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("} else {\n")
|
||||
->indent()
|
||||
;
|
||||
|
||||
$this->compileAsset($compiler, $this->getAttribute('asset'), $this->getAttribute('name'));
|
||||
|
||||
$compiler
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
;
|
||||
} elseif ($combine) {
|
||||
$this->compileAsset($compiler, $this->getAttribute('asset'), $this->getAttribute('name'));
|
||||
} else {
|
||||
$this->compileDebug($compiler);
|
||||
}
|
||||
|
||||
$compiler
|
||||
->write('unset($context[')
|
||||
->repr($this->getAttribute('var_name'))
|
||||
->raw("]);\n")
|
||||
;
|
||||
}
|
||||
|
||||
protected function compileDebug(\Twig_Compiler $compiler)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($this->getAttribute('asset') as $leaf) {
|
||||
$leafName = $this->getAttribute('name').'_'.$i++;
|
||||
$this->compileAsset($compiler, $leaf, $leafName);
|
||||
}
|
||||
}
|
||||
|
||||
protected function compileAsset(\Twig_Compiler $compiler, AssetInterface $asset, $name)
|
||||
{
|
||||
if ($vars = $asset->getVars()) {
|
||||
$compiler->write("// check variable conditions\n");
|
||||
|
||||
foreach ($vars as $var) {
|
||||
$compiler
|
||||
->write("if (!isset(\$context['assetic']['vars']['$var'])) {\n")
|
||||
->indent()
|
||||
->write("throw new \RuntimeException(sprintf('The asset \"".$name."\" expected variable \"".$var."\" to be set, but got only these vars: %s. Did you set-up a value supplier?', isset(\$context['assetic']['vars']) && \$context['assetic']['vars'] ? implode(', ', \$context['assetic']['vars']) : '# none #'));\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
;
|
||||
}
|
||||
|
||||
$compiler->raw("\n");
|
||||
}
|
||||
|
||||
$compiler
|
||||
->write("// asset \"$name\"\n")
|
||||
->write('$context[')
|
||||
->repr($this->getAttribute('var_name'))
|
||||
->raw('] = ')
|
||||
;
|
||||
|
||||
$this->compileAssetUrl($compiler, $asset, $name);
|
||||
|
||||
$compiler
|
||||
->raw(";\n")
|
||||
->subcompile($this->getNode('body'))
|
||||
;
|
||||
}
|
||||
|
||||
protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
|
||||
{
|
||||
if (!$vars = $asset->getVars()) {
|
||||
$compiler->repr($asset->getTargetPath());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw("strtr(")
|
||||
->string($asset->getTargetPath())
|
||||
->raw(", array(");
|
||||
|
||||
$first = true;
|
||||
foreach ($vars as $var) {
|
||||
if (!$first) {
|
||||
$compiler->raw(", ");
|
||||
}
|
||||
$first = false;
|
||||
|
||||
$compiler
|
||||
->string("{".$var."}")
|
||||
->raw(" => \$context['assetic']['vars']['$var']")
|
||||
;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw("))")
|
||||
;
|
||||
}
|
||||
}
|
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Factory\AssetFactory;
|
||||
|
||||
class AsseticTokenParser extends \Twig_TokenParser
|
||||
{
|
||||
private $factory;
|
||||
private $tag;
|
||||
private $output;
|
||||
private $single;
|
||||
private $extensions;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Attributes can be added to the tag by passing names as the options
|
||||
* array. These values, if found, will be passed to the factory and node.
|
||||
*
|
||||
* @param AssetFactory $factory The asset factory
|
||||
* @param string $tag The tag name
|
||||
* @param string $output The default output string
|
||||
* @param Boolean $single Whether to force a single asset
|
||||
* @param array $extensions Additional attribute names to look for
|
||||
*/
|
||||
public function __construct(AssetFactory $factory, $tag, $output, $single = false, array $extensions = array())
|
||||
{
|
||||
$this->factory = $factory;
|
||||
$this->tag = $tag;
|
||||
$this->output = $output;
|
||||
$this->single = $single;
|
||||
$this->extensions = $extensions;
|
||||
}
|
||||
|
||||
public function parse(\Twig_Token $token)
|
||||
{
|
||||
$inputs = array();
|
||||
$filters = array();
|
||||
$name = null;
|
||||
$attributes = array(
|
||||
'output' => $this->output,
|
||||
'var_name' => 'asset_url',
|
||||
'vars' => array(),
|
||||
);
|
||||
|
||||
$stream = $this->parser->getStream();
|
||||
while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
|
||||
if ($stream->test(\Twig_Token::STRING_TYPE)) {
|
||||
// '@jquery', 'js/src/core/*', 'js/src/extra.js'
|
||||
$inputs[] = $stream->next()->getValue();
|
||||
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'filter')) {
|
||||
// filter='yui_js'
|
||||
$stream->next();
|
||||
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
|
||||
$filters = array_merge($filters, array_filter(array_map('trim', explode(',', $stream->expect(\Twig_Token::STRING_TYPE)->getValue()))));
|
||||
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'output')) {
|
||||
// output='js/packed/*.js' OR output='js/core.js'
|
||||
$stream->next();
|
||||
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
|
||||
$attributes['output'] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
|
||||
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'name')) {
|
||||
// name='core_js'
|
||||
$stream->next();
|
||||
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
|
||||
$name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
|
||||
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'as')) {
|
||||
// as='the_url'
|
||||
$stream->next();
|
||||
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
|
||||
$attributes['var_name'] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
|
||||
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'debug')) {
|
||||
// debug=true
|
||||
$stream->next();
|
||||
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
|
||||
$attributes['debug'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, array('true', 'false'))->getValue();
|
||||
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'combine')) {
|
||||
// combine=true
|
||||
$stream->next();
|
||||
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
|
||||
$attributes['combine'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, array('true', 'false'))->getValue();
|
||||
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'vars')) {
|
||||
// vars=['locale','browser']
|
||||
$stream->next();
|
||||
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
|
||||
$stream->expect(\Twig_Token::PUNCTUATION_TYPE, '[');
|
||||
|
||||
while ($stream->test(\Twig_Token::STRING_TYPE)) {
|
||||
$attributes['vars'][] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
|
||||
|
||||
if (!$stream->test(\Twig_Token::PUNCTUATION_TYPE, ',')) {
|
||||
break;
|
||||
}
|
||||
|
||||
$stream->next();
|
||||
}
|
||||
|
||||
$stream->expect(\Twig_Token::PUNCTUATION_TYPE, ']');
|
||||
} elseif ($stream->test(\Twig_Token::NAME_TYPE, $this->extensions)) {
|
||||
// an arbitrary configured attribute
|
||||
$key = $stream->next()->getValue();
|
||||
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
|
||||
$attributes[$key] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
|
||||
} else {
|
||||
$token = $stream->getCurrent();
|
||||
throw new \Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', \Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $stream->getFilename());
|
||||
}
|
||||
}
|
||||
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$body = $this->parser->subparse(array($this, 'testEndTag'), true);
|
||||
|
||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
if ($this->single && 1 < count($inputs)) {
|
||||
$inputs = array_slice($inputs, -1);
|
||||
}
|
||||
|
||||
if (!$name) {
|
||||
$name = $this->factory->generateAssetName($inputs, $filters, $attributes);
|
||||
}
|
||||
|
||||
$asset = $this->factory->createAsset($inputs, $filters, $attributes + array('name' => $name));
|
||||
|
||||
return $this->createBodyNode($asset, $body, $inputs, $filters, $name, $attributes, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
public function testEndTag(\Twig_Token $token)
|
||||
{
|
||||
return $token->test(array('end'.$this->getTag()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AssetInterface $asset
|
||||
* @param \Twig_Node $body
|
||||
* @param array $inputs
|
||||
* @param array $filters
|
||||
* @param string $name
|
||||
* @param array $attributes
|
||||
* @param int $lineno
|
||||
* @param string $tag
|
||||
*
|
||||
* @return \Twig_Node
|
||||
*/
|
||||
protected function createBodyNode(AssetInterface $asset, \Twig_Node $body, array $inputs, array $filters, $name, array $attributes = array(), $lineno = 0, $tag = null)
|
||||
{
|
||||
$reflector = new \ReflectionMethod($this, 'createNode');
|
||||
|
||||
if (__CLASS__ !== $reflector->getDeclaringClass()->name) {
|
||||
@trigger_error(sprintf('Overwriting %s::createNode is deprecated since 1.3. Overwrite %s instead.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->createNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
|
||||
}
|
||||
|
||||
return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AssetInterface $asset
|
||||
* @param \Twig_NodeInterface $body
|
||||
* @param array $inputs
|
||||
* @param array $filters
|
||||
* @param string $name
|
||||
* @param array $attributes
|
||||
* @param int $lineno
|
||||
* @param string $tag
|
||||
*
|
||||
* @return \Twig_Node
|
||||
*
|
||||
* @deprecated since 1.3.0, to be removed in 2.0. Use createBodyNode instead.
|
||||
*/
|
||||
protected function createNode(AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes = array(), $lineno = 0, $tag = null)
|
||||
{
|
||||
@trigger_error(sprintf('The %s method is deprecated since 1.3 and will be removed in 2.0. Use createBodyNode instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
if (!$body instanceof \Twig_Node) {
|
||||
throw new \InvalidArgumentException('The body must be a Twig_Node. Custom implementations of Twig_NodeInterface are not supported.');
|
||||
}
|
||||
|
||||
return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
use Assetic\Factory\Loader\FormulaLoaderInterface;
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Loads asset formulae from Twig templates.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class TwigFormulaLoader implements FormulaLoaderInterface
|
||||
{
|
||||
private $twig;
|
||||
private $logger;
|
||||
|
||||
public function __construct(\Twig_Environment $twig, LoggerInterface $logger = null)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function load(ResourceInterface $resource)
|
||||
{
|
||||
try {
|
||||
$tokens = $this->twig->tokenize(new \Twig_Source($resource->getContent(), (string) $resource));
|
||||
$nodes = $this->twig->parse($tokens);
|
||||
} catch (\Exception $e) {
|
||||
if ($this->logger) {
|
||||
$this->logger->error(sprintf('The template "%s" contains an error: %s', $resource, $e->getMessage()));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
return $this->loadNode($nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads assets from the supplied node.
|
||||
*
|
||||
* @param \Twig_Node $node
|
||||
*
|
||||
* @return array An array of asset formulae indexed by name
|
||||
*/
|
||||
private function loadNode(\Twig_Node $node)
|
||||
{
|
||||
$formulae = array();
|
||||
|
||||
if ($node instanceof AsseticNode) {
|
||||
$formulae[$node->getAttribute('name')] = array(
|
||||
$node->getAttribute('inputs'),
|
||||
$node->getAttribute('filters'),
|
||||
array(
|
||||
'output' => $node->getAttribute('asset')->getTargetPath(),
|
||||
'name' => $node->getAttribute('name'),
|
||||
'debug' => $node->getAttribute('debug'),
|
||||
'combine' => $node->getAttribute('combine'),
|
||||
'vars' => $node->getAttribute('vars'),
|
||||
),
|
||||
);
|
||||
} elseif ($node instanceof AsseticFilterNode) {
|
||||
$name = $node->getAttribute('name');
|
||||
|
||||
$arguments = array();
|
||||
foreach ($node->getNode('arguments') as $argument) {
|
||||
$arguments[] = eval('return '.$this->twig->compile($argument).';');
|
||||
}
|
||||
|
||||
$invoker = $this->twig->getExtension('Assetic\Extension\Twig\AsseticExtension')->getFilterInvoker($name);
|
||||
|
||||
$inputs = isset($arguments[0]) ? (array) $arguments[0] : array();
|
||||
$filters = $invoker->getFilters();
|
||||
$options = array_replace($invoker->getOptions(), isset($arguments[1]) ? $arguments[1] : array());
|
||||
|
||||
if (!isset($options['name'])) {
|
||||
$options['name'] = $invoker->getFactory()->generateAssetName($inputs, $filters, $options);
|
||||
}
|
||||
|
||||
$formulae[$options['name']] = array($inputs, $filters, $options);
|
||||
}
|
||||
|
||||
foreach ($node as $child) {
|
||||
if ($child instanceof \Twig_Node) {
|
||||
$formulae += $this->loadNode($child);
|
||||
}
|
||||
}
|
||||
|
||||
if ($node->hasAttribute('embedded_templates')) {
|
||||
foreach ($node->getAttribute('embedded_templates') as $child) {
|
||||
$formulae += $this->loadNode($child);
|
||||
}
|
||||
}
|
||||
|
||||
return $formulae;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
|
||||
/**
|
||||
* A Twig template resource.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class TwigResource implements ResourceInterface
|
||||
{
|
||||
private $loader;
|
||||
private $name;
|
||||
|
||||
public function __construct(\Twig_LoaderInterface $loader, $name)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
try {
|
||||
return method_exists($this->loader, 'getSourceContext')
|
||||
? $this->loader->getSourceContext($this->name)->getCode()
|
||||
: $this->loader->getSource($this->name);
|
||||
} catch (\Twig_Error_Loader $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function isFresh($timestamp)
|
||||
{
|
||||
try {
|
||||
return $this->loader->isFresh($this->name, $timestamp);
|
||||
} catch (\Twig_Error_Loader $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Extension\Twig;
|
||||
|
||||
use Assetic\ValueSupplierInterface;
|
||||
|
||||
/**
|
||||
* Container for values initialized lazily from a ValueSupplierInterface.
|
||||
*
|
||||
* @author Christophe Coevoet <stof@notk.org>
|
||||
*/
|
||||
class ValueContainer implements \ArrayAccess, \IteratorAggregate, \Countable
|
||||
{
|
||||
private $values;
|
||||
private $valueSupplier;
|
||||
|
||||
public function __construct(ValueSupplierInterface $valueSupplier)
|
||||
{
|
||||
$this->valueSupplier = $valueSupplier;
|
||||
}
|
||||
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return array_key_exists($offset, $this->values);
|
||||
}
|
||||
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
if (!array_key_exists($offset, $this->values)) {
|
||||
throw new \OutOfRangeException(sprintf('The variable "%s" does not exist.', $offset));
|
||||
}
|
||||
|
||||
return $this->values[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
throw new \BadMethodCallException('The ValueContainer is read-only.');
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
throw new \BadMethodCallException('The ValueContainer is read-only.');
|
||||
}
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return new \ArrayIterator($this->values);
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return count($this->values);
|
||||
}
|
||||
|
||||
private function initialize()
|
||||
{
|
||||
if (null === $this->values) {
|
||||
$this->values = $this->valueSupplier->getValues();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,424 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory;
|
||||
|
||||
use Assetic\Asset\AssetCollection;
|
||||
use Assetic\Asset\AssetCollectionInterface;
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Asset\AssetReference;
|
||||
use Assetic\Asset\FileAsset;
|
||||
use Assetic\Asset\GlobAsset;
|
||||
use Assetic\Asset\HttpAsset;
|
||||
use Assetic\AssetManager;
|
||||
use Assetic\Factory\Worker\WorkerInterface;
|
||||
use Assetic\Filter\DependencyExtractorInterface;
|
||||
use Assetic\FilterManager;
|
||||
|
||||
/**
|
||||
* The asset factory creates asset objects.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class AssetFactory
|
||||
{
|
||||
private $root;
|
||||
private $debug;
|
||||
private $output;
|
||||
private $workers;
|
||||
private $am;
|
||||
private $fm;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $root The default root directory
|
||||
* @param Boolean $debug Filters prefixed with a "?" will be omitted in debug mode
|
||||
*/
|
||||
public function __construct($root, $debug = false)
|
||||
{
|
||||
$this->root = rtrim($root, '/');
|
||||
$this->debug = $debug;
|
||||
$this->output = 'assetic/*';
|
||||
$this->workers = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets debug mode for the current factory.
|
||||
*
|
||||
* @param Boolean $debug Debug mode
|
||||
*/
|
||||
public function setDebug($debug)
|
||||
{
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the factory is in debug mode.
|
||||
*
|
||||
* @return Boolean Debug mode
|
||||
*/
|
||||
public function isDebug()
|
||||
{
|
||||
return $this->debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default output string.
|
||||
*
|
||||
* @param string $output The default output string
|
||||
*/
|
||||
public function setDefaultOutput($output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a factory worker.
|
||||
*
|
||||
* @param WorkerInterface $worker A worker
|
||||
*/
|
||||
public function addWorker(WorkerInterface $worker)
|
||||
{
|
||||
$this->workers[] = $worker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current asset manager.
|
||||
*
|
||||
* @return AssetManager|null The asset manager
|
||||
*/
|
||||
public function getAssetManager()
|
||||
{
|
||||
return $this->am;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the asset manager to use when creating asset references.
|
||||
*
|
||||
* @param AssetManager $am The asset manager
|
||||
*/
|
||||
public function setAssetManager(AssetManager $am)
|
||||
{
|
||||
$this->am = $am;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current filter manager.
|
||||
*
|
||||
* @return FilterManager|null The filter manager
|
||||
*/
|
||||
public function getFilterManager()
|
||||
{
|
||||
return $this->fm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filter manager to use when adding filters.
|
||||
*
|
||||
* @param FilterManager $fm The filter manager
|
||||
*/
|
||||
public function setFilterManager(FilterManager $fm)
|
||||
{
|
||||
$this->fm = $fm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new asset.
|
||||
*
|
||||
* Prefixing a filter name with a question mark will cause it to be
|
||||
* omitted when the factory is in debug mode.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * output: An output string
|
||||
* * name: An asset name for interpolation in output patterns
|
||||
* * debug: Forces debug mode on or off for this asset
|
||||
* * root: An array or string of more root directories
|
||||
*
|
||||
* @param array|string $inputs An array of input strings
|
||||
* @param array|string $filters An array of filter names
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return AssetCollection An asset collection
|
||||
*/
|
||||
public function createAsset($inputs = array(), $filters = array(), array $options = array())
|
||||
{
|
||||
if (!is_array($inputs)) {
|
||||
$inputs = array($inputs);
|
||||
}
|
||||
|
||||
if (!is_array($filters)) {
|
||||
$filters = array($filters);
|
||||
}
|
||||
|
||||
if (!isset($options['output'])) {
|
||||
$options['output'] = $this->output;
|
||||
}
|
||||
|
||||
if (!isset($options['vars'])) {
|
||||
$options['vars'] = array();
|
||||
}
|
||||
|
||||
if (!isset($options['debug'])) {
|
||||
$options['debug'] = $this->debug;
|
||||
}
|
||||
|
||||
if (!isset($options['root'])) {
|
||||
$options['root'] = array($this->root);
|
||||
} else {
|
||||
if (!is_array($options['root'])) {
|
||||
$options['root'] = array($options['root']);
|
||||
}
|
||||
|
||||
$options['root'][] = $this->root;
|
||||
}
|
||||
|
||||
if (!isset($options['name'])) {
|
||||
$options['name'] = $this->generateAssetName($inputs, $filters, $options);
|
||||
}
|
||||
|
||||
$asset = $this->createAssetCollection(array(), $options);
|
||||
$extensions = array();
|
||||
|
||||
// inner assets
|
||||
foreach ($inputs as $input) {
|
||||
if (is_array($input)) {
|
||||
// nested formula
|
||||
$asset->add(call_user_func_array(array($this, 'createAsset'), $input));
|
||||
} else {
|
||||
$asset->add($this->parseInput($input, $options));
|
||||
$extensions[pathinfo($input, PATHINFO_EXTENSION)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// filters
|
||||
foreach ($filters as $filter) {
|
||||
if ('?' != $filter[0]) {
|
||||
$asset->ensureFilter($this->getFilter($filter));
|
||||
} elseif (!$options['debug']) {
|
||||
$asset->ensureFilter($this->getFilter(substr($filter, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
// append variables
|
||||
if (!empty($options['vars'])) {
|
||||
$toAdd = array();
|
||||
foreach ($options['vars'] as $var) {
|
||||
if (false !== strpos($options['output'], '{'.$var.'}')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$toAdd[] = '{'.$var.'}';
|
||||
}
|
||||
|
||||
if ($toAdd) {
|
||||
$options['output'] = str_replace('*', '*.'.implode('.', $toAdd), $options['output']);
|
||||
}
|
||||
}
|
||||
|
||||
// append consensus extension if missing
|
||||
if (1 == count($extensions) && !pathinfo($options['output'], PATHINFO_EXTENSION) && $extension = key($extensions)) {
|
||||
$options['output'] .= '.'.$extension;
|
||||
}
|
||||
|
||||
// output --> target url
|
||||
$asset->setTargetPath(str_replace('*', $options['name'], $options['output']));
|
||||
|
||||
// apply workers and return
|
||||
return $this->applyWorkers($asset);
|
||||
}
|
||||
|
||||
public function generateAssetName($inputs, $filters, $options = array())
|
||||
{
|
||||
foreach (array_diff(array_keys($options), array('output', 'debug', 'root')) as $key) {
|
||||
unset($options[$key]);
|
||||
}
|
||||
|
||||
ksort($options);
|
||||
|
||||
return substr(sha1(serialize($inputs).serialize($filters).serialize($options)), 0, 7);
|
||||
}
|
||||
|
||||
public function getLastModified(AssetInterface $asset)
|
||||
{
|
||||
$mtime = 0;
|
||||
foreach ($asset instanceof AssetCollectionInterface ? $asset : array($asset) as $leaf) {
|
||||
$mtime = max($mtime, $leaf->getLastModified());
|
||||
|
||||
if (!$filters = $leaf->getFilters()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$prevFilters = array();
|
||||
foreach ($filters as $filter) {
|
||||
$prevFilters[] = $filter;
|
||||
|
||||
if (!$filter instanceof DependencyExtractorInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// extract children from leaf after running all preceeding filters
|
||||
$clone = clone $leaf;
|
||||
$clone->clearFilters();
|
||||
foreach (array_slice($prevFilters, 0, -1) as $prevFilter) {
|
||||
$clone->ensureFilter($prevFilter);
|
||||
}
|
||||
$clone->load();
|
||||
|
||||
foreach ($filter->getChildren($this, $clone->getContent(), $clone->getSourceDirectory()) as $child) {
|
||||
$mtime = max($mtime, $this->getLastModified($child));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $mtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an input string string into an asset.
|
||||
*
|
||||
* The input string can be one of the following:
|
||||
*
|
||||
* * A reference: If the string starts with an "at" sign it will be interpreted as a reference to an asset in the asset manager
|
||||
* * An absolute URL: If the string contains "://" or starts with "//" it will be interpreted as an HTTP asset
|
||||
* * A glob: If the string contains a "*" it will be interpreted as a glob
|
||||
* * A path: Otherwise the string is interpreted as a filesystem path
|
||||
*
|
||||
* Both globs and paths will be absolutized using the current root directory.
|
||||
*
|
||||
* @param string $input An input string
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return AssetInterface An asset
|
||||
*/
|
||||
protected function parseInput($input, array $options = array())
|
||||
{
|
||||
if ('@' == $input[0]) {
|
||||
return $this->createAssetReference(substr($input, 1));
|
||||
}
|
||||
|
||||
if (false !== strpos($input, '://') || 0 === strpos($input, '//')) {
|
||||
return $this->createHttpAsset($input, $options['vars']);
|
||||
}
|
||||
|
||||
if (self::isAbsolutePath($input)) {
|
||||
if ($root = self::findRootDir($input, $options['root'])) {
|
||||
$path = ltrim(substr($input, strlen($root)), '/');
|
||||
} else {
|
||||
$path = null;
|
||||
}
|
||||
} else {
|
||||
$root = $this->root;
|
||||
$path = $input;
|
||||
$input = $this->root.'/'.$path;
|
||||
}
|
||||
|
||||
if (false !== strpos($input, '*')) {
|
||||
return $this->createGlobAsset($input, $root, $options['vars']);
|
||||
}
|
||||
|
||||
return $this->createFileAsset($input, $root, $path, $options['vars']);
|
||||
}
|
||||
|
||||
protected function createAssetCollection(array $assets = array(), array $options = array())
|
||||
{
|
||||
return new AssetCollection($assets, array(), null, isset($options['vars']) ? $options['vars'] : array());
|
||||
}
|
||||
|
||||
protected function createAssetReference($name)
|
||||
{
|
||||
if (!$this->am) {
|
||||
throw new \LogicException('There is no asset manager.');
|
||||
}
|
||||
|
||||
return new AssetReference($this->am, $name);
|
||||
}
|
||||
|
||||
protected function createHttpAsset($sourceUrl, $vars)
|
||||
{
|
||||
return new HttpAsset($sourceUrl, array(), false, $vars);
|
||||
}
|
||||
|
||||
protected function createGlobAsset($glob, $root = null, $vars)
|
||||
{
|
||||
return new GlobAsset($glob, array(), $root, $vars);
|
||||
}
|
||||
|
||||
protected function createFileAsset($source, $root = null, $path = null, $vars)
|
||||
{
|
||||
return new FileAsset($source, array(), $root, $path, $vars);
|
||||
}
|
||||
|
||||
protected function getFilter($name)
|
||||
{
|
||||
if (!$this->fm) {
|
||||
throw new \LogicException('There is no filter manager.');
|
||||
}
|
||||
|
||||
return $this->fm->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters an asset collection through the factory workers.
|
||||
*
|
||||
* Each leaf asset will be processed first, followed by the asset
|
||||
* collection itself.
|
||||
*
|
||||
* @param AssetCollectionInterface $asset An asset collection
|
||||
*
|
||||
* @return AssetCollectionInterface
|
||||
*/
|
||||
private function applyWorkers(AssetCollectionInterface $asset)
|
||||
{
|
||||
foreach ($asset as $leaf) {
|
||||
foreach ($this->workers as $worker) {
|
||||
$retval = $worker->process($leaf, $this);
|
||||
|
||||
if ($retval instanceof AssetInterface && $leaf !== $retval) {
|
||||
$asset->replaceLeaf($leaf, $retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->workers as $worker) {
|
||||
$retval = $worker->process($asset, $this);
|
||||
|
||||
if ($retval instanceof AssetInterface) {
|
||||
$asset = $retval;
|
||||
}
|
||||
}
|
||||
|
||||
return $asset instanceof AssetCollectionInterface ? $asset : $this->createAssetCollection(array($asset));
|
||||
}
|
||||
|
||||
private static function isAbsolutePath($path)
|
||||
{
|
||||
return '/' == $path[0] || '\\' == $path[0] || (3 < strlen($path) && ctype_alpha($path[0]) && $path[1] == ':' && ('\\' == $path[2] || '/' == $path[2]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops through the root directories and returns the first match.
|
||||
*
|
||||
* @param string $path An absolute path
|
||||
* @param array $roots An array of root directories
|
||||
*
|
||||
* @return string|null The matching root directory, if found
|
||||
*/
|
||||
private static function findRootDir($path, array $roots)
|
||||
{
|
||||
foreach ($roots as $root) {
|
||||
if (0 === strpos($path, $root)) {
|
||||
return $root;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\AssetManager;
|
||||
use Assetic\Factory\Loader\FormulaLoaderInterface;
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
|
||||
/**
|
||||
* A lazy asset manager is a composition of a factory and many formula loaders.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class LazyAssetManager extends AssetManager
|
||||
{
|
||||
private $factory;
|
||||
private $loaders;
|
||||
private $resources;
|
||||
private $formulae;
|
||||
private $loaded;
|
||||
private $loading;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param AssetFactory $factory The asset factory
|
||||
* @param array $loaders An array of loaders indexed by alias
|
||||
*/
|
||||
public function __construct(AssetFactory $factory, $loaders = array())
|
||||
{
|
||||
$this->factory = $factory;
|
||||
$this->loaders = array();
|
||||
$this->resources = array();
|
||||
$this->formulae = array();
|
||||
$this->loaded = false;
|
||||
$this->loading = false;
|
||||
|
||||
foreach ($loaders as $alias => $loader) {
|
||||
$this->setLoader($alias, $loader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a loader to the asset manager.
|
||||
*
|
||||
* @param string $alias An alias for the loader
|
||||
* @param FormulaLoaderInterface $loader A loader
|
||||
*/
|
||||
public function setLoader($alias, FormulaLoaderInterface $loader)
|
||||
{
|
||||
$this->loaders[$alias] = $loader;
|
||||
$this->loaded = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a resource to the asset manager.
|
||||
*
|
||||
* @param ResourceInterface $resource A resource
|
||||
* @param string $loader The loader alias for this resource
|
||||
*/
|
||||
public function addResource(ResourceInterface $resource, $loader)
|
||||
{
|
||||
$this->resources[$loader][] = $resource;
|
||||
$this->loaded = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of resources.
|
||||
*
|
||||
* @return array An array of resources
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
$resources = array();
|
||||
foreach ($this->resources as $r) {
|
||||
$resources = array_merge($resources, $r);
|
||||
}
|
||||
|
||||
return $resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for an asset formula.
|
||||
*
|
||||
* @param string $name An asset name
|
||||
*
|
||||
* @return Boolean If there is a formula
|
||||
*/
|
||||
public function hasFormula($name)
|
||||
{
|
||||
if (!$this->loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
return isset($this->formulae[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an asset's formula.
|
||||
*
|
||||
* @param string $name An asset name
|
||||
*
|
||||
* @return array The formula
|
||||
*
|
||||
* @throws \InvalidArgumentException If there is no formula by that name
|
||||
*/
|
||||
public function getFormula($name)
|
||||
{
|
||||
if (!$this->loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
if (!isset($this->formulae[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('There is no "%s" formula.', $name));
|
||||
}
|
||||
|
||||
return $this->formulae[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a formula on the asset manager.
|
||||
*
|
||||
* @param string $name An asset name
|
||||
* @param array $formula A formula
|
||||
*/
|
||||
public function setFormula($name, array $formula)
|
||||
{
|
||||
$this->formulae[$name] = $formula;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads formulae from resources.
|
||||
*
|
||||
* @throws \LogicException If a resource has been added to an invalid loader
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
if ($this->loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($diff = array_diff(array_keys($this->resources), array_keys($this->loaders))) {
|
||||
throw new \LogicException('The following loader(s) are not registered: '.implode(', ', $diff));
|
||||
}
|
||||
|
||||
$this->loading = true;
|
||||
|
||||
foreach ($this->resources as $loader => $resources) {
|
||||
foreach ($resources as $resource) {
|
||||
$this->formulae = array_replace($this->formulae, $this->loaders[$loader]->load($resource));
|
||||
}
|
||||
}
|
||||
|
||||
$this->loaded = true;
|
||||
$this->loading = false;
|
||||
}
|
||||
|
||||
public function get($name)
|
||||
{
|
||||
if (!$this->loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
if (!parent::has($name) && isset($this->formulae[$name])) {
|
||||
list($inputs, $filters, $options) = $this->formulae[$name];
|
||||
$options['name'] = $name;
|
||||
parent::set($name, $this->factory->createAsset($inputs, $filters, $options));
|
||||
}
|
||||
|
||||
return parent::get($name);
|
||||
}
|
||||
|
||||
public function has($name)
|
||||
{
|
||||
if (!$this->loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
return isset($this->formulae[$name]) || parent::has($name);
|
||||
}
|
||||
|
||||
public function getNames()
|
||||
{
|
||||
if (!$this->loaded) {
|
||||
$this->load();
|
||||
}
|
||||
|
||||
return array_unique(array_merge(parent::getNames(), array_keys($this->formulae)));
|
||||
}
|
||||
|
||||
public function isDebug()
|
||||
{
|
||||
return $this->factory->isDebug();
|
||||
}
|
||||
|
||||
public function getLastModified(AssetInterface $asset)
|
||||
{
|
||||
return $this->factory->getLastModified($asset);
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Loader;
|
||||
|
||||
use Assetic\Factory\AssetFactory;
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
use Assetic\Util\FilesystemUtils;
|
||||
|
||||
/**
|
||||
* Loads asset formulae from PHP files.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
abstract class BasePhpFormulaLoader implements FormulaLoaderInterface
|
||||
{
|
||||
protected $factory;
|
||||
protected $prototypes;
|
||||
|
||||
public function __construct(AssetFactory $factory)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
$this->prototypes = array();
|
||||
|
||||
foreach ($this->registerPrototypes() as $prototype => $options) {
|
||||
$this->addPrototype($prototype, $options);
|
||||
}
|
||||
}
|
||||
|
||||
public function addPrototype($prototype, array $options = array())
|
||||
{
|
||||
$tokens = token_get_all('<?php '.$prototype);
|
||||
array_shift($tokens);
|
||||
|
||||
$this->prototypes[$prototype] = array($tokens, $options);
|
||||
}
|
||||
|
||||
public function load(ResourceInterface $resource)
|
||||
{
|
||||
if (!$nbProtos = count($this->prototypes)) {
|
||||
throw new \LogicException('There are no prototypes registered.');
|
||||
}
|
||||
|
||||
$buffers = array_fill(0, $nbProtos, '');
|
||||
$bufferLevels = array_fill(0, $nbProtos, 0);
|
||||
$buffersInWildcard = array();
|
||||
|
||||
$tokens = token_get_all($resource->getContent());
|
||||
$calls = array();
|
||||
|
||||
while ($token = array_shift($tokens)) {
|
||||
$current = self::tokenToString($token);
|
||||
// loop through each prototype (by reference)
|
||||
foreach (array_keys($this->prototypes) as $i) {
|
||||
$prototype = & $this->prototypes[$i][0];
|
||||
$options = $this->prototypes[$i][1];
|
||||
$buffer = & $buffers[$i];
|
||||
$level = & $bufferLevels[$i];
|
||||
|
||||
if (isset($buffersInWildcard[$i])) {
|
||||
switch ($current) {
|
||||
case '(': ++$level; break;
|
||||
case ')': --$level; break;
|
||||
}
|
||||
|
||||
$buffer .= $current;
|
||||
|
||||
if (!$level) {
|
||||
$calls[] = array($buffer.';', $options);
|
||||
$buffer = '';
|
||||
unset($buffersInWildcard[$i]);
|
||||
}
|
||||
} elseif ($current == self::tokenToString(current($prototype))) {
|
||||
$buffer .= $current;
|
||||
if ('*' == self::tokenToString(next($prototype))) {
|
||||
$buffersInWildcard[$i] = true;
|
||||
++$level;
|
||||
}
|
||||
} else {
|
||||
reset($prototype);
|
||||
unset($buffersInWildcard[$i]);
|
||||
$buffer = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formulae = array();
|
||||
foreach ($calls as $call) {
|
||||
$formulae += call_user_func_array(array($this, 'processCall'), $call);
|
||||
}
|
||||
|
||||
return $formulae;
|
||||
}
|
||||
|
||||
private function processCall($call, array $protoOptions = array())
|
||||
{
|
||||
$tmp = FilesystemUtils::createTemporaryFile('php_formula_loader');
|
||||
file_put_contents($tmp, implode("\n", array(
|
||||
'<?php',
|
||||
$this->registerSetupCode(),
|
||||
$call,
|
||||
'echo serialize($_call);',
|
||||
)));
|
||||
$args = unserialize(shell_exec('php '.escapeshellarg($tmp)));
|
||||
unlink($tmp);
|
||||
|
||||
$inputs = isset($args[0]) ? self::argumentToArray($args[0]) : array();
|
||||
$filters = isset($args[1]) ? self::argumentToArray($args[1]) : array();
|
||||
$options = isset($args[2]) ? $args[2] : array();
|
||||
|
||||
if (!isset($options['debug'])) {
|
||||
$options['debug'] = $this->factory->isDebug();
|
||||
}
|
||||
|
||||
if (!is_array($options)) {
|
||||
throw new \RuntimeException('The third argument must be omitted, null or an array.');
|
||||
}
|
||||
|
||||
// apply the prototype options
|
||||
$options += $protoOptions;
|
||||
|
||||
if (!isset($options['name'])) {
|
||||
$options['name'] = $this->factory->generateAssetName($inputs, $filters, $options);
|
||||
}
|
||||
|
||||
return array($options['name'] => array($inputs, $filters, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of prototypical calls and options.
|
||||
*
|
||||
* @return array Prototypes and options
|
||||
*/
|
||||
abstract protected function registerPrototypes();
|
||||
|
||||
/**
|
||||
* Returns setup code for the reflection scriptlet.
|
||||
*
|
||||
* @return string Some PHP setup code
|
||||
*/
|
||||
abstract protected function registerSetupCode();
|
||||
|
||||
protected static function tokenToString($token)
|
||||
{
|
||||
return is_array($token) ? $token[1] : $token;
|
||||
}
|
||||
|
||||
protected static function argumentToArray($argument)
|
||||
{
|
||||
return is_array($argument) ? $argument : array_filter(array_map('trim', explode(',', $argument)));
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Loader;
|
||||
|
||||
use Assetic\Cache\ConfigCache;
|
||||
use Assetic\Factory\Resource\IteratorResourceInterface;
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
|
||||
/**
|
||||
* Adds a caching layer to a loader.
|
||||
*
|
||||
* A cached formula loader is a composition of a formula loader and a cache.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class CachedFormulaLoader implements FormulaLoaderInterface
|
||||
{
|
||||
private $loader;
|
||||
private $configCache;
|
||||
private $debug;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* When the loader is in debug mode it will ensure the cached formulae
|
||||
* are fresh before returning them.
|
||||
*
|
||||
* @param FormulaLoaderInterface $loader A formula loader
|
||||
* @param ConfigCache $configCache A config cache
|
||||
* @param Boolean $debug The debug mode
|
||||
*/
|
||||
public function __construct(FormulaLoaderInterface $loader, ConfigCache $configCache, $debug = false)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->configCache = $configCache;
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
public function load(ResourceInterface $resources)
|
||||
{
|
||||
if (!$resources instanceof IteratorResourceInterface) {
|
||||
$resources = array($resources);
|
||||
}
|
||||
|
||||
$formulae = array();
|
||||
|
||||
foreach ($resources as $resource) {
|
||||
$id = (string) $resource;
|
||||
if (!$this->configCache->has($id) || ($this->debug && !$resource->isFresh($this->configCache->getTimestamp($id)))) {
|
||||
$formulae += $this->loader->load($resource);
|
||||
$this->configCache->set($id, $formulae);
|
||||
} else {
|
||||
$formulae += $this->configCache->get($id);
|
||||
}
|
||||
}
|
||||
|
||||
return $formulae;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Loader;
|
||||
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
|
||||
/**
|
||||
* Loads formulae.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface FormulaLoaderInterface
|
||||
{
|
||||
/**
|
||||
* Loads formulae from a resource.
|
||||
*
|
||||
* Formulae should be loaded the same regardless of the current debug
|
||||
* mode. Debug considerations should happen downstream.
|
||||
*
|
||||
* @param ResourceInterface $resource A resource
|
||||
*
|
||||
* @return array An array of formulae
|
||||
*/
|
||||
public function load(ResourceInterface $resource);
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Loader;
|
||||
|
||||
/**
|
||||
* Loads asset formulae from PHP files.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class FunctionCallsFormulaLoader extends BasePhpFormulaLoader
|
||||
{
|
||||
protected function registerPrototypes()
|
||||
{
|
||||
return array(
|
||||
'assetic_javascripts(*)' => array('output' => 'js/*.js'),
|
||||
'assetic_stylesheets(*)' => array('output' => 'css/*.css'),
|
||||
'assetic_image(*)' => array('output' => 'images/*'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function registerSetupCode()
|
||||
{
|
||||
return <<<'EOF'
|
||||
function assetic_javascripts()
|
||||
{
|
||||
global $_call;
|
||||
$_call = func_get_args();
|
||||
}
|
||||
|
||||
function assetic_stylesheets()
|
||||
{
|
||||
global $_call;
|
||||
$_call = func_get_args();
|
||||
}
|
||||
|
||||
function assetic_image()
|
||||
{
|
||||
global $_call;
|
||||
$_call = func_get_args();
|
||||
}
|
||||
|
||||
EOF;
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Resource;
|
||||
|
||||
/**
|
||||
* Coalesces multiple directories together into one merged resource.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class CoalescingDirectoryResource implements IteratorResourceInterface
|
||||
{
|
||||
private $directories;
|
||||
|
||||
public function __construct($directories)
|
||||
{
|
||||
$this->directories = array();
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
$this->addDirectory($directory);
|
||||
}
|
||||
}
|
||||
|
||||
public function addDirectory(IteratorResourceInterface $directory)
|
||||
{
|
||||
$this->directories[] = $directory;
|
||||
}
|
||||
|
||||
public function isFresh($timestamp)
|
||||
{
|
||||
foreach ($this->getFileResources() as $file) {
|
||||
if (!$file->isFresh($timestamp)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
$parts = array();
|
||||
foreach ($this->getFileResources() as $file) {
|
||||
$parts[] = $file->getContent();
|
||||
}
|
||||
|
||||
return implode("\n", $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string to uniquely identify the current resource.
|
||||
*
|
||||
* @return string An identifying string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$parts = array();
|
||||
foreach ($this->directories as $directory) {
|
||||
$parts[] = (string) $directory;
|
||||
}
|
||||
|
||||
return implode(',', $parts);
|
||||
}
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->getFileResources());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relative version of a filename.
|
||||
*
|
||||
* @param ResourceInterface $file The file
|
||||
* @param ResourceInterface $directory The directory
|
||||
*
|
||||
* @return string The name to compare with files from other directories
|
||||
*/
|
||||
protected function getRelativeName(ResourceInterface $file, ResourceInterface $directory)
|
||||
{
|
||||
return substr((string) $file, strlen((string) $directory));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the coalesce.
|
||||
*
|
||||
* @return array An array of file resources
|
||||
*/
|
||||
private function getFileResources()
|
||||
{
|
||||
$paths = array();
|
||||
|
||||
foreach ($this->directories as $directory) {
|
||||
foreach ($directory as $file) {
|
||||
$relative = $this->getRelativeName($file, $directory);
|
||||
|
||||
if (!isset($paths[$relative])) {
|
||||
$paths[$relative] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($paths);
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Resource;
|
||||
|
||||
/**
|
||||
* A resource is something formulae can be loaded from.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class DirectoryResource implements IteratorResourceInterface
|
||||
{
|
||||
private $path;
|
||||
private $pattern;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $path A directory path
|
||||
* @param string $pattern A filename pattern
|
||||
*/
|
||||
public function __construct($path, $pattern = null)
|
||||
{
|
||||
if (DIRECTORY_SEPARATOR != substr($path, -1)) {
|
||||
$path .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$this->path = $path;
|
||||
$this->pattern = $pattern;
|
||||
}
|
||||
|
||||
public function isFresh($timestamp)
|
||||
{
|
||||
if (!is_dir($this->path) || filemtime($this->path) > $timestamp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this as $resource) {
|
||||
if (!$resource->isFresh($timestamp)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the combined content of all inner resources.
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
$content = array();
|
||||
foreach ($this as $resource) {
|
||||
$content[] = $resource->getContent();
|
||||
}
|
||||
|
||||
return implode("\n", $content);
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return is_dir($this->path)
|
||||
? new DirectoryResourceIterator($this->getInnerIterator())
|
||||
: new \EmptyIterator();
|
||||
}
|
||||
|
||||
protected function getInnerIterator()
|
||||
{
|
||||
return new DirectoryResourceFilterIterator(new \RecursiveDirectoryIterator($this->path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS), $this->pattern);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An iterator that converts file objects into file resources.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
* @access private
|
||||
*/
|
||||
class DirectoryResourceIterator extends \RecursiveIteratorIterator
|
||||
{
|
||||
public function current()
|
||||
{
|
||||
return new FileResource(parent::current()->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters files by a basename pattern.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
* @access private
|
||||
*/
|
||||
class DirectoryResourceFilterIterator extends \RecursiveFilterIterator
|
||||
{
|
||||
protected $pattern;
|
||||
|
||||
public function __construct(\RecursiveDirectoryIterator $iterator, $pattern = null)
|
||||
{
|
||||
parent::__construct($iterator);
|
||||
|
||||
$this->pattern = $pattern;
|
||||
}
|
||||
|
||||
public function accept()
|
||||
{
|
||||
$file = $this->current();
|
||||
$name = $file->getBasename();
|
||||
|
||||
if ($file->isDir()) {
|
||||
return '.' != $name[0];
|
||||
}
|
||||
|
||||
return null === $this->pattern || 0 < preg_match($this->pattern, $name);
|
||||
}
|
||||
|
||||
public function getChildren()
|
||||
{
|
||||
return new self(new \RecursiveDirectoryIterator($this->current()->getPathname(), \RecursiveDirectoryIterator::FOLLOW_SYMLINKS), $this->pattern);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Resource;
|
||||
|
||||
/**
|
||||
* A resource is something formulae can be loaded from.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class FileResource implements ResourceInterface
|
||||
{
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $path The path to a file
|
||||
*/
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
public function isFresh($timestamp)
|
||||
{
|
||||
return file_exists($this->path) && filemtime($this->path) <= $timestamp;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return file_exists($this->path) ? file_get_contents($this->path) : '';
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Resource;
|
||||
|
||||
/**
|
||||
* A resource is something formulae can be loaded from.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface IteratorResourceInterface extends ResourceInterface, \IteratorAggregate
|
||||
{
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Resource;
|
||||
|
||||
/**
|
||||
* A resource is something formulae can be loaded from.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface ResourceInterface
|
||||
{
|
||||
/**
|
||||
* Checks if a timestamp represents the latest resource.
|
||||
*
|
||||
* @param integer $timestamp A UNIX timestamp
|
||||
*
|
||||
* @return Boolean True if the timestamp is up to date
|
||||
*/
|
||||
public function isFresh($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the content of the resource.
|
||||
*
|
||||
* @return string The content
|
||||
*/
|
||||
public function getContent();
|
||||
|
||||
/**
|
||||
* Returns a unique string for the current resource.
|
||||
*
|
||||
* @return string A unique string to identity the current resource
|
||||
*/
|
||||
public function __toString();
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Worker;
|
||||
|
||||
use Assetic\Asset\AssetCollectionInterface;
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Factory\AssetFactory;
|
||||
|
||||
/**
|
||||
* Adds cache busting code
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class CacheBustingWorker implements WorkerInterface
|
||||
{
|
||||
private $separator;
|
||||
|
||||
public function __construct($separator = '-')
|
||||
{
|
||||
$this->separator = $separator;
|
||||
}
|
||||
|
||||
public function process(AssetInterface $asset, AssetFactory $factory)
|
||||
{
|
||||
if (!$path = $asset->getTargetPath()) {
|
||||
// no path to work with
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$search = pathinfo($path, PATHINFO_EXTENSION)) {
|
||||
// nothing to replace
|
||||
return;
|
||||
}
|
||||
|
||||
$replace = $this->separator.$this->getHash($asset, $factory).'.'.$search;
|
||||
if (preg_match('/'.preg_quote($replace, '/').'$/', $path)) {
|
||||
// already replaced
|
||||
return;
|
||||
}
|
||||
|
||||
$asset->setTargetPath(
|
||||
preg_replace('/\.'.preg_quote($search, '/').'$/', $replace, $path)
|
||||
);
|
||||
}
|
||||
|
||||
protected function getHash(AssetInterface $asset, AssetFactory $factory)
|
||||
{
|
||||
$hash = hash_init('sha1');
|
||||
|
||||
hash_update($hash, $factory->getLastModified($asset));
|
||||
|
||||
if ($asset instanceof AssetCollectionInterface) {
|
||||
foreach ($asset as $i => $leaf) {
|
||||
$sourcePath = $leaf->getSourcePath();
|
||||
hash_update($hash, $sourcePath ?: $i);
|
||||
}
|
||||
}
|
||||
|
||||
return substr(hash_final($hash), 0, 7);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Worker;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Factory\AssetFactory;
|
||||
use Assetic\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* Applies a filter to an asset based on a source and/or target path match.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
* @todo A better asset-matcher mechanism
|
||||
*/
|
||||
class EnsureFilterWorker implements WorkerInterface
|
||||
{
|
||||
const CHECK_SOURCE = 1;
|
||||
const CHECK_TARGET = 2;
|
||||
|
||||
private $pattern;
|
||||
private $filter;
|
||||
private $flags;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $pattern A regex for checking the asset's target URL
|
||||
* @param FilterInterface $filter A filter to apply if the regex matches
|
||||
* @param integer $flags Flags for what to check
|
||||
*/
|
||||
public function __construct($pattern, FilterInterface $filter, $flags = null)
|
||||
{
|
||||
if (null === $flags) {
|
||||
$flags = self::CHECK_SOURCE | self::CHECK_TARGET;
|
||||
}
|
||||
|
||||
$this->pattern = $pattern;
|
||||
$this->filter = $filter;
|
||||
$this->flags = $flags;
|
||||
}
|
||||
|
||||
public function process(AssetInterface $asset, AssetFactory $factory)
|
||||
{
|
||||
if (
|
||||
(self::CHECK_SOURCE === (self::CHECK_SOURCE & $this->flags) && preg_match($this->pattern, $asset->getSourcePath()))
|
||||
||
|
||||
(self::CHECK_TARGET === (self::CHECK_TARGET & $this->flags) && preg_match($this->pattern, $asset->getTargetPath()))
|
||||
) {
|
||||
$asset->ensureFilter($this->filter);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Worker;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Factory\AssetFactory;
|
||||
|
||||
/**
|
||||
* Assets are passed through factory workers before leaving the factory.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface WorkerInterface
|
||||
{
|
||||
/**
|
||||
* Processes an asset.
|
||||
*
|
||||
* @param AssetInterface $asset An asset
|
||||
* @param AssetFactory $factory The factory
|
||||
*
|
||||
* @return AssetInterface|null May optionally return a replacement asset
|
||||
*/
|
||||
public function process(AssetInterface $asset, AssetFactory $factory);
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2013 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Exception\FilterException;
|
||||
use Assetic\Util\FilesystemUtils;
|
||||
|
||||
/**
|
||||
* Parses CSS and adds vendor prefixes to rules using values from the Can I Use website
|
||||
*
|
||||
* @link https://github.com/ai/autoprefixer
|
||||
* @author Alex Vasilenko <aa.vasilenko@gmail.com>
|
||||
*/
|
||||
class AutoprefixerFilter extends BaseNodeFilter
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $autoprefixerBin;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $browsers = array();
|
||||
|
||||
public function __construct($autoprefixerBin)
|
||||
{
|
||||
$this->autoprefixerBin = $autoprefixerBin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $browsers
|
||||
*/
|
||||
public function setBrowsers(array $browsers)
|
||||
{
|
||||
$this->browsers = $browsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $browser
|
||||
*/
|
||||
public function addBrowser($browser)
|
||||
{
|
||||
$this->browsers[] = $browser;
|
||||
}
|
||||
|
||||
public function filterLoad(AssetInterface $asset)
|
||||
{
|
||||
$input = $asset->getContent();
|
||||
$pb = $this->createProcessBuilder(array($this->autoprefixerBin));
|
||||
|
||||
$pb->setInput($input);
|
||||
if ($this->browsers) {
|
||||
$pb->add('-b')->add(implode(',', $this->browsers));
|
||||
}
|
||||
|
||||
$output = FilesystemUtils::createTemporaryFile('autoprefixer');
|
||||
$pb->add('-o')->add($output);
|
||||
|
||||
$proc = $pb->getProcess();
|
||||
if (0 !== $proc->run()) {
|
||||
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
|
||||
}
|
||||
|
||||
$asset->setContent(file_get_contents($output));
|
||||
unlink($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters an asset just before it's dumped.
|
||||
*
|
||||
* @param AssetInterface $asset An asset
|
||||
*/
|
||||
public function filterDump(AssetInterface $asset)
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Assetic\Util\CssUtils;
|
||||
|
||||
/**
|
||||
* An abstract filter for dealing with CSS.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
abstract class BaseCssFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* @see CssUtils::filterReferences()
|
||||
*/
|
||||
protected function filterReferences($content, $callback, $limit = -1, &$count = 0)
|
||||
{
|
||||
return CssUtils::filterReferences($content, $callback, $limit, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CssUtils::filterUrls()
|
||||
*/
|
||||
protected function filterUrls($content, $callback, $limit = -1, &$count = 0)
|
||||
{
|
||||
return CssUtils::filterUrls($content, $callback, $limit, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CssUtils::filterImports()
|
||||
*/
|
||||
protected function filterImports($content, $callback, $limit = -1, &$count = 0, $includeUrl = true)
|
||||
{
|
||||
return CssUtils::filterImports($content, $callback, $limit, $count, $includeUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CssUtils::filterIEFilters()
|
||||
*/
|
||||
protected function filterIEFilters($content, $callback, $limit = -1, &$count = 0)
|
||||
{
|
||||
return CssUtils::filterIEFilters($content, $callback, $limit, $count);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
abstract class BaseNodeFilter extends BaseProcessFilter
|
||||
{
|
||||
private $nodePaths = array();
|
||||
|
||||
public function getNodePaths()
|
||||
{
|
||||
return $this->nodePaths;
|
||||
}
|
||||
|
||||
public function setNodePaths(array $nodePaths)
|
||||
{
|
||||
$this->nodePaths = $nodePaths;
|
||||
}
|
||||
|
||||
public function addNodePath($nodePath)
|
||||
{
|
||||
$this->nodePaths[] = $nodePath;
|
||||
}
|
||||
|
||||
protected function createProcessBuilder(array $arguments = array())
|
||||
{
|
||||
$pb = parent::createProcessBuilder($arguments);
|
||||
|
||||
if ($this->nodePaths) {
|
||||
$this->mergeEnv($pb);
|
||||
$pb->setEnv('NODE_PATH', implode(PATH_SEPARATOR, $this->nodePaths));
|
||||
}
|
||||
|
||||
return $pb;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Symfony\Component\Process\ProcessBuilder;
|
||||
|
||||
/**
|
||||
* An external process based filter which provides a way to set a timeout on the process.
|
||||
*/
|
||||
abstract class BaseProcessFilter implements FilterInterface
|
||||
{
|
||||
private $timeout;
|
||||
|
||||
/**
|
||||
* Set the process timeout.
|
||||
*
|
||||
* @param int $timeout The timeout for the process
|
||||
*/
|
||||
public function setTimeout($timeout)
|
||||
{
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new process builder.
|
||||
*
|
||||
* @param array $arguments An optional array of arguments
|
||||
*
|
||||
* @return ProcessBuilder A new process builder
|
||||
*/
|
||||
protected function createProcessBuilder(array $arguments = array())
|
||||
{
|
||||
$pb = new ProcessBuilder($arguments);
|
||||
|
||||
if (null !== $this->timeout) {
|
||||
$pb->setTimeout($this->timeout);
|
||||
}
|
||||
|
||||
return $pb;
|
||||
}
|
||||
|
||||
protected function mergeEnv(ProcessBuilder $pb)
|
||||
{
|
||||
foreach (array_filter($_SERVER, 'is_scalar') as $key => $value) {
|
||||
$pb->setEnv($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Factory\AssetFactory;
|
||||
|
||||
/**
|
||||
* A filter that wraps callables.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class CallablesFilter implements FilterInterface, DependencyExtractorInterface
|
||||
{
|
||||
private $loader;
|
||||
private $dumper;
|
||||
private $extractor;
|
||||
|
||||
/**
|
||||
* @param callable|null $loader
|
||||
* @param callable|null $dumper
|
||||
* @param callable|null $extractor
|
||||
*/
|
||||
public function __construct($loader = null, $dumper = null, $extractor = null)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->dumper = $dumper;
|
||||
$this->extractor = $extractor;
|
||||
}
|
||||
|
||||
public function filterLoad(AssetInterface $asset)
|
||||
{
|
||||
if (null !== $callable = $this->loader) {
|
||||
$callable($asset);
|
||||
}
|
||||
}
|
||||
|
||||
public function filterDump(AssetInterface $asset)
|
||||
{
|
||||
if (null !== $callable = $this->dumper) {
|
||||
$callable($asset);
|
||||
}
|
||||
}
|
||||
|
||||
public function getChildren(AssetFactory $factory, $content, $loadPath = null)
|
||||
{
|
||||
if (null !== $callable = $this->extractor) {
|
||||
return $callable($factory, $content, $loadPath);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
}
|
@ -0,0 +1,343 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Exception\FilterException;
|
||||
|
||||
/**
|
||||
* CleanCss filter.
|
||||
*
|
||||
* @link https://github.com/jakubpawlowicz/clean-css
|
||||
* @author Jakub Pawlowicz <http://JakubPawlowicz.com>
|
||||
*/
|
||||
class CleanCssFilter extends BaseNodeFilter
|
||||
{
|
||||
private $cleanCssBin;
|
||||
private $nodeBin;
|
||||
|
||||
private $keepLineBreaks;
|
||||
private $compatibility;
|
||||
private $debug;
|
||||
private $rootPath;
|
||||
private $skipImport = true;
|
||||
private $timeout;
|
||||
private $semanticMerging;
|
||||
private $roundingPrecision;
|
||||
private $removeSpecialComments;
|
||||
private $onlyKeepFirstSpecialComment;
|
||||
private $skipAdvanced;
|
||||
private $skipAggresiveMerging;
|
||||
private $skipImportFrom;
|
||||
private $mediaMerging;
|
||||
private $skipRebase;
|
||||
private $skipRestructuring;
|
||||
private $skipShorthandCompacting;
|
||||
private $sourceMap;
|
||||
private $sourceMapInlineSources;
|
||||
|
||||
|
||||
/**
|
||||
* @param string $cleanCssBin Absolute path to the cleancss executable
|
||||
* @param string $nodeBin Absolute path to the folder containg node.js executable
|
||||
*/
|
||||
public function __construct($cleanCssBin = '/usr/bin/cleancss', $nodeBin = null)
|
||||
{
|
||||
$this->cleanCssBin = $cleanCssBin;
|
||||
$this->nodeBin = $nodeBin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep line breaks
|
||||
* @param bool $keepLineBreaks True to enable
|
||||
*/
|
||||
public function setKeepLineBreaks($keepLineBreaks)
|
||||
{
|
||||
$this->keepLineBreaks = $keepLineBreaks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all special comments
|
||||
* @param bool $removeSpecialComments True to enable
|
||||
*/ // i.e. /*! comment */
|
||||
public function setRemoveSpecialComments($removeSpecialComments)
|
||||
{
|
||||
$this->removeSpecialComments = $removeSpecialComments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all special comments except the first one
|
||||
* @param bool $onlyKeepFirstSpecialComment True to enable
|
||||
*/
|
||||
public function setOnlyKeepFirstSpecialComment($onlyKeepFirstSpecialComment)
|
||||
{
|
||||
$this->onlyKeepFirstSpecialComment = $onlyKeepFirstSpecialComment;
|
||||
}
|
||||
/**
|
||||
* Enables unsafe mode by assuming BEM-like semantic stylesheets (warning, this may break your styling!)
|
||||
* @param bool $semanticMerging True to enable
|
||||
*/
|
||||
public function setSemanticMerging($semanticMerging)
|
||||
{
|
||||
$this->semanticMerging = $semanticMerging;
|
||||
}
|
||||
|
||||
/**
|
||||
* A root path to which resolve absolute @import rules
|
||||
* @param string $rootPath
|
||||
*/
|
||||
public function setRootPath($rootPath)
|
||||
{
|
||||
$this->rootPath = $rootPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable @import processing
|
||||
* @param bool $skipImport True to enable
|
||||
*/
|
||||
public function setSkipImport($skipImport)
|
||||
{
|
||||
$this->skipImport = $skipImport;
|
||||
}
|
||||
/**
|
||||
* Per connection timeout when fetching remote @imports; defaults to 5 seconds
|
||||
* @param int $timeout
|
||||
*/
|
||||
public function setTimeout($timeout)
|
||||
{
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable URLs rebasing
|
||||
* @param bool $skipRebase True to enable
|
||||
*/
|
||||
public function setSkipRebase($skipRebase)
|
||||
{
|
||||
$this->skipRebase = $skipRebase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable restructuring optimizations
|
||||
* @param bool $skipRestructuring True to enable
|
||||
*/
|
||||
public function setSkipRestructuring($skipRestructuring)
|
||||
{
|
||||
$this->skipRestructuring = $skipRestructuring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable shorthand compacting
|
||||
* @param bool $skipShorthandCompacting True to enable
|
||||
*/
|
||||
public function setSkipShorthandCompacting($skipShorthandCompacting)
|
||||
{
|
||||
$this->skipShorthandCompacting = $skipShorthandCompacting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables building input's source map
|
||||
* @param bool $sourceMap True to enable
|
||||
*/
|
||||
public function setSourceMap($sourceMap)
|
||||
{
|
||||
$this->sourceMap = $sourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables inlining sources inside source maps
|
||||
* @param bool $sourceMapInlineSources True to enable
|
||||
*/
|
||||
public function setSourceMapInlineSources($sourceMapInlineSources)
|
||||
{
|
||||
$this->sourceMapInlineSources = $sourceMapInlineSources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable advanced optimizations - selector & property merging, reduction, etc.
|
||||
* @param bool $skipAdvanced True to enable
|
||||
*/
|
||||
public function setSkipAdvanced($skipAdvanced)
|
||||
{
|
||||
$this->skipAdvanced = $skipAdvanced;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable properties merging based on their order
|
||||
* @param bool $skipAggresiveMerging True to enable
|
||||
*/
|
||||
public function setSkipAggresiveMerging($skipAggresiveMerging)
|
||||
{
|
||||
$this->skipAggresiveMerging = $skipAggresiveMerging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable @import processing for specified rules
|
||||
* @param string $skipImportFrom
|
||||
*/
|
||||
public function setSkipImportFrom($skipImportFrom)
|
||||
{
|
||||
$this->skipImportFrom = $skipImportFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable @media merging
|
||||
* @param bool $mediaMerging True to enable
|
||||
*/
|
||||
public function setMediaMerging($mediaMerging)
|
||||
{
|
||||
$this->mediaMerging = $mediaMerging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds to `N` decimal places. Defaults to 2. -1 disables rounding.
|
||||
* @param int $roundingPrecision
|
||||
*/
|
||||
public function setRoundingPrecision($roundingPrecision)
|
||||
{
|
||||
$this->roundingPrecision = $roundingPrecision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force compatibility mode (see https://github.com/jakubpawlowicz/clean-css/blob/master/README.md#how-to-set-compatibility-mode for advanced examples)
|
||||
* @param string $compatibility
|
||||
*/
|
||||
public function setCompatibility($compatibility)
|
||||
{
|
||||
$this->compatibility = $compatibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows debug information (minification time & compression efficiency)
|
||||
* @param bool $debug True to enable
|
||||
*/
|
||||
public function setDebug($debug)
|
||||
{
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Assetic\Filter\FilterInterface::filterLoad()
|
||||
*/
|
||||
public function filterLoad(AssetInterface $asset)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the asset through CleanCss
|
||||
*
|
||||
* @see Assetic\Filter\FilterInterface::filterDump()
|
||||
*/
|
||||
public function filterDump(AssetInterface $asset)
|
||||
{
|
||||
$pb = $this->createProcessBuilder($this->nodeBin
|
||||
? array($this->nodeBin, $this->cleanCssBin)
|
||||
: array($this->cleanCssBin));
|
||||
|
||||
if ($this->keepLineBreaks) {
|
||||
$pb->add('--keep-line-breaks');
|
||||
}
|
||||
|
||||
if ($this->compatibility) {
|
||||
$pb->add('--compatibility ' .$this->compatibility);
|
||||
}
|
||||
|
||||
if ($this->debug) {
|
||||
$pb->add('--debug');
|
||||
}
|
||||
|
||||
if ($this->rootPath) {
|
||||
$pb->add('--root ' .$this->rootPath);
|
||||
}
|
||||
|
||||
if ($this->skipImport) {
|
||||
$pb->add('--skip-import');
|
||||
}
|
||||
|
||||
if ($this->timeout) {
|
||||
$pb->add('--timeout ' .$this->timeout);
|
||||
}
|
||||
|
||||
if ($this->roundingPrecision) {
|
||||
$pb->add('--rounding-precision ' .$this->roundingPrecision);
|
||||
}
|
||||
|
||||
if ($this->removeSpecialComments) {
|
||||
$pb->add('--s0');
|
||||
}
|
||||
|
||||
if ($this->onlyKeepFirstSpecialComment) {
|
||||
$pb->add('--s1');
|
||||
}
|
||||
|
||||
if ($this->semanticMerging) {
|
||||
$pb->add('--semantic-merging');
|
||||
}
|
||||
|
||||
if ($this->skipAdvanced) {
|
||||
$pb->add('--skip-advanced');
|
||||
}
|
||||
|
||||
if ($this->skipAggresiveMerging) {
|
||||
$pb->add('--skip-aggressive-merging');
|
||||
}
|
||||
|
||||
if ($this->skipImportFrom) {
|
||||
$pb->add('--skip-import-from ' .$this->skipImportFrom);
|
||||
}
|
||||
|
||||
if ($this->mediaMerging) {
|
||||
$pb->add('--skip-media-merging');
|
||||
}
|
||||
|
||||
if ($this->skipRebase) {
|
||||
$pb->add('--skip-rebase');
|
||||
}
|
||||
|
||||
if ($this->skipRestructuring) {
|
||||
$pb->add('--skip-restructuring');
|
||||
}
|
||||
|
||||
if ($this->skipShorthandCompacting) {
|
||||
$pb->add('--skip-shorthand-compacting');
|
||||
}
|
||||
|
||||
if ($this->sourceMap) {
|
||||
$pb->add('--source-map');
|
||||
}
|
||||
|
||||
if ($this->sourceMapInlineSources) {
|
||||
$pb->add('--source-map-inline-sources');
|
||||
}
|
||||
// input and output files
|
||||
$input = tempnam(sys_get_temp_dir(), 'input');
|
||||
|
||||
file_put_contents($input, $asset->getContent());
|
||||
$pb->add($input);
|
||||
|
||||
$proc = $pb->getProcess();
|
||||
$code = $proc->run();
|
||||
unlink($input);
|
||||
|
||||
if (127 === $code) {
|
||||
throw new \RuntimeException('Path to node executable could not be resolved.');
|
||||
}
|
||||
|
||||
if (0 !== $code) {
|
||||
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
|
||||
}
|
||||
|
||||
$asset->setContent($proc->getOutput());
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Exception\FilterException;
|
||||
use Assetic\Util\FilesystemUtils;
|
||||
|
||||
/**
|
||||
* Compiles CoffeeScript into Javascript.
|
||||
*
|
||||
* @link http://coffeescript.org/
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class CoffeeScriptFilter extends BaseNodeFilter
|
||||
{
|
||||
private $coffeeBin;
|
||||
private $nodeBin;
|
||||
|
||||
// coffee options
|
||||
private $bare;
|
||||
private $noHeader;
|
||||
|
||||
public function __construct($coffeeBin = '/usr/bin/coffee', $nodeBin = null)
|
||||
{
|
||||
$this->coffeeBin = $coffeeBin;
|
||||
$this->nodeBin = $nodeBin;
|
||||
}
|
||||
|
||||
public function setBare($bare)
|
||||
{
|
||||
$this->bare = $bare;
|
||||
}
|
||||
|
||||
public function setNoHeader($noHeader)
|
||||
{
|
||||
$this->noHeader = $noHeader;
|
||||
}
|
||||
|
||||
public function filterLoad(AssetInterface $asset)
|
||||
{
|
||||
$input = FilesystemUtils::createTemporaryFile('coffee');
|
||||
file_put_contents($input, $asset->getContent());
|
||||
|
||||
$pb = $this->createProcessBuilder($this->nodeBin
|
||||
? array($this->nodeBin, $this->coffeeBin)
|
||||
: array($this->coffeeBin));
|
||||
|
||||
$pb->add('-cp');
|
||||
|
||||
if ($this->bare) {
|
||||
$pb->add('--bare');
|
||||
}
|
||||
|
||||
if ($this->noHeader) {
|
||||
$pb->add('--no-header');
|
||||
}
|
||||
|
||||
$pb->add($input);
|
||||
$proc = $pb->getProcess();
|
||||
$code = $proc->run();
|
||||
unlink($input);
|
||||
|
||||
if (0 !== $code) {
|
||||
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
|
||||
}
|
||||
|
||||
$asset->setContent($proc->getOutput());
|
||||
}
|
||||
|
||||
public function filterDump(AssetInterface $asset)
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,391 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Exception\FilterException;
|
||||
use Assetic\Filter\Sass\BaseSassFilter;
|
||||
use Assetic\Util\FilesystemUtils;
|
||||
|
||||
/**
|
||||
* Loads Compass files.
|
||||
*
|
||||
* @link http://compass-style.org/
|
||||
* @author Maxime Thirouin <maxime.thirouin@gmail.com>
|
||||
*/
|
||||
class CompassFilter extends BaseSassFilter
|
||||
{
|
||||
private $compassPath;
|
||||
private $rubyPath;
|
||||
private $scss;
|
||||
|
||||
// sass options
|
||||
private $unixNewlines;
|
||||
private $debugInfo;
|
||||
private $cacheLocation;
|
||||
private $noCache;
|
||||
|
||||
// compass options
|
||||
private $force;
|
||||
private $style;
|
||||
private $quiet;
|
||||
private $boring;
|
||||
private $noLineComments;
|
||||
private $imagesDir;
|
||||
private $javascriptsDir;
|
||||
private $fontsDir;
|
||||
private $relativeAssets;
|
||||
|
||||
// compass configuration file options
|
||||
private $plugins = array();
|
||||
private $httpPath;
|
||||
private $httpImagesPath;
|
||||
private $httpFontsPath;
|
||||
private $httpGeneratedImagesPath;
|
||||
private $generatedImagesPath;
|
||||
private $httpJavascriptsPath;
|
||||
private $homeEnv = true;
|
||||
|
||||
public function __construct($compassPath = '/usr/bin/compass', $rubyPath = null)
|
||||
{
|
||||
$this->compassPath = $compassPath;
|
||||
$this->rubyPath = $rubyPath;
|
||||
$this->cacheLocation = FilesystemUtils::getTemporaryDirectory();
|
||||
|
||||
if ('cli' !== php_sapi_name()) {
|
||||
$this->boring = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function setScss($scss)
|
||||
{
|
||||
$this->scss = $scss;
|
||||
}
|
||||
|
||||
// sass options setters
|
||||
public function setUnixNewlines($unixNewlines)
|
||||
{
|
||||
$this->unixNewlines = $unixNewlines;
|
||||
}
|
||||
|
||||
public function setDebugInfo($debugInfo)
|
||||
{
|
||||
$this->debugInfo = $debugInfo;
|
||||
}
|
||||
|
||||
public function setCacheLocation($cacheLocation)
|
||||
{
|
||||
$this->cacheLocation = $cacheLocation;
|
||||
}
|
||||
|
||||
public function setNoCache($noCache)
|
||||
{
|
||||
$this->noCache = $noCache;
|
||||
}
|
||||
|
||||
// compass options setters
|
||||
public function setForce($force)
|
||||
{
|
||||
$this->force = $force;
|
||||
}
|
||||
|
||||
public function setStyle($style)
|
||||
{
|
||||
$this->style = $style;
|
||||
}
|
||||
|
||||
public function setQuiet($quiet)
|
||||
{
|
||||
$this->quiet = $quiet;
|
||||
}
|
||||
|
||||
public function setBoring($boring)
|
||||
{
|
||||
$this->boring = $boring;
|
||||
}
|
||||
|
||||
public function setNoLineComments($noLineComments)
|
||||
{
|
||||
$this->noLineComments = $noLineComments;
|
||||
}
|
||||
|
||||
public function setImagesDir($imagesDir)
|
||||
{
|
||||
$this->imagesDir = $imagesDir;
|
||||
}
|
||||
|
||||
public function setJavascriptsDir($javascriptsDir)
|
||||
{
|
||||
$this->javascriptsDir = $javascriptsDir;
|
||||
}
|
||||
|
||||
public function setFontsDir($fontsDir)
|
||||
{
|
||||
$this->fontsDir = $fontsDir;
|
||||
}
|
||||
|
||||
// compass configuration file options setters
|
||||
public function setPlugins(array $plugins)
|
||||
{
|
||||
$this->plugins = $plugins;
|
||||
}
|
||||
|
||||
public function addPlugin($plugin)
|
||||
{
|
||||
$this->plugins[] = $plugin;
|
||||
}
|
||||
|
||||
public function setHttpPath($httpPath)
|
||||
{
|
||||
$this->httpPath = $httpPath;
|
||||
}
|
||||
|
||||
public function setHttpImagesPath($httpImagesPath)
|
||||
{
|
||||
$this->httpImagesPath = $httpImagesPath;
|
||||
}
|
||||
|
||||
public function setHttpFontsPath($httpFontsPath)
|
||||
{
|
||||
$this->httpFontsPath = $httpFontsPath;
|
||||
}
|
||||
|
||||
public function setHttpGeneratedImagesPath($httpGeneratedImagesPath)
|
||||
{
|
||||
$this->httpGeneratedImagesPath = $httpGeneratedImagesPath;
|
||||
}
|
||||
|
||||
public function setGeneratedImagesPath($generatedImagesPath)
|
||||
{
|
||||
$this->generatedImagesPath = $generatedImagesPath;
|
||||
}
|
||||
|
||||
public function setHttpJavascriptsPath($httpJavascriptsPath)
|
||||
{
|
||||
$this->httpJavascriptsPath = $httpJavascriptsPath;
|
||||
}
|
||||
|
||||
public function setHomeEnv($homeEnv)
|
||||
{
|
||||
$this->homeEnv = $homeEnv;
|
||||
}
|
||||
|
||||
public function setRelativeAssets($relativeAssets)
|
||||
{
|
||||
$this->relativeAssets = $relativeAssets;
|
||||
}
|
||||
|
||||
public function filterLoad(AssetInterface $asset)
|
||||
{
|
||||
$loadPaths = $this->loadPaths;
|
||||
if ($dir = $asset->getSourceDirectory()) {
|
||||
$loadPaths[] = $dir;
|
||||
}
|
||||
|
||||
$tempDir = $this->cacheLocation ? $this->cacheLocation : FilesystemUtils::getTemporaryDirectory();
|
||||
|
||||
$compassProcessArgs = array(
|
||||
$this->compassPath,
|
||||
'compile',
|
||||
$tempDir,
|
||||
);
|
||||
if (null !== $this->rubyPath) {
|
||||
$compassProcessArgs = array_merge(explode(' ', $this->rubyPath), $compassProcessArgs);
|
||||
}
|
||||
|
||||
$pb = $this->createProcessBuilder($compassProcessArgs);
|
||||
|
||||
if ($this->force) {
|
||||
$pb->add('--force');
|
||||
}
|
||||
|
||||
if ($this->style) {
|
||||
$pb->add('--output-style')->add($this->style);
|
||||
}
|
||||
|
||||
if ($this->quiet) {
|
||||
$pb->add('--quiet');
|
||||
}
|
||||
|
||||
if ($this->boring) {
|
||||
$pb->add('--boring');
|
||||
}
|
||||
|
||||
if ($this->noLineComments) {
|
||||
$pb->add('--no-line-comments');
|
||||
}
|
||||
|
||||
// these three options are not passed into the config file
|
||||
// because like this, compass adapts this to be xxx_dir or xxx_path
|
||||
// whether it's an absolute path or not
|
||||
if ($this->imagesDir) {
|
||||
$pb->add('--images-dir')->add($this->imagesDir);
|
||||
}
|
||||
|
||||
if ($this->relativeAssets) {
|
||||
$pb->add('--relative-assets');
|
||||
}
|
||||
|
||||
if ($this->javascriptsDir) {
|
||||
$pb->add('--javascripts-dir')->add($this->javascriptsDir);
|
||||
}
|
||||
|
||||
if ($this->fontsDir) {
|
||||
$pb->add('--fonts-dir')->add($this->fontsDir);
|
||||
}
|
||||
|
||||
// options in config file
|
||||
$optionsConfig = array();
|
||||
|
||||
if (!empty($loadPaths)) {
|
||||
$optionsConfig['additional_import_paths'] = $loadPaths;
|
||||
}
|
||||
|
||||
if ($this->unixNewlines) {
|
||||
$optionsConfig['sass_options']['unix_newlines'] = true;
|
||||
}
|
||||
|
||||
if ($this->debugInfo) {
|
||||
$optionsConfig['sass_options']['debug_info'] = true;
|
||||
}
|
||||
|
||||
if ($this->cacheLocation) {
|
||||
$optionsConfig['sass_options']['cache_location'] = $this->cacheLocation;
|
||||
}
|
||||
|
||||
if ($this->noCache) {
|
||||
$optionsConfig['sass_options']['no_cache'] = true;
|
||||
}
|
||||
|
||||
if ($this->httpPath) {
|
||||
$optionsConfig['http_path'] = $this->httpPath;
|
||||
}
|
||||
|
||||
if ($this->httpImagesPath) {
|
||||
$optionsConfig['http_images_path'] = $this->httpImagesPath;
|
||||
}
|
||||
|
||||
if ($this->httpFontsPath) {
|
||||
$optionsConfig['http_fonts_path'] = $this->httpFontsPath;
|
||||
}
|
||||
|
||||
if ($this->httpGeneratedImagesPath) {
|
||||
$optionsConfig['http_generated_images_path'] = $this->httpGeneratedImagesPath;
|
||||
}
|
||||
|
||||
if ($this->generatedImagesPath) {
|
||||
$optionsConfig['generated_images_path'] = $this->generatedImagesPath;
|
||||
}
|
||||
|
||||
if ($this->httpJavascriptsPath) {
|
||||
$optionsConfig['http_javascripts_path'] = $this->httpJavascriptsPath;
|
||||
}
|
||||
|
||||
// options in configuration file
|
||||
if (count($optionsConfig)) {
|
||||
$config = array();
|
||||
foreach ($this->plugins as $plugin) {
|
||||
$config[] = sprintf("require '%s'", addcslashes($plugin, '\\'));
|
||||
}
|
||||
foreach ($optionsConfig as $name => $value) {
|
||||
if (!is_array($value)) {
|
||||
$config[] = sprintf('%s = "%s"', $name, addcslashes($value, '\\'));
|
||||
} elseif (!empty($value)) {
|
||||
$config[] = sprintf('%s = %s', $name, $this->formatArrayToRuby($value));
|
||||
}
|
||||
}
|
||||
|
||||
$configFile = tempnam($tempDir, 'assetic_compass');
|
||||
file_put_contents($configFile, implode("\n", $config)."\n");
|
||||
$pb->add('--config')->add($configFile);
|
||||
}
|
||||
|
||||
$pb->add('--sass-dir')->add('')->add('--css-dir')->add('');
|
||||
|
||||
// compass choose the type (sass or scss from the filename)
|
||||
if (null !== $this->scss) {
|
||||
$type = $this->scss ? 'scss' : 'sass';
|
||||
} elseif ($path = $asset->getSourcePath()) {
|
||||
// FIXME: what if the extension is something else?
|
||||
$type = pathinfo($path, PATHINFO_EXTENSION);
|
||||
} else {
|
||||
$type = 'scss';
|
||||
}
|
||||
|
||||
$tempName = tempnam($tempDir, 'assetic_compass');
|
||||
unlink($tempName); // FIXME: don't use tempnam() here
|
||||
|
||||
// input
|
||||
$input = $tempName.'.'.$type;
|
||||
|
||||
// work-around for https://github.com/chriseppstein/compass/issues/748
|
||||
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
|
||||
$input = str_replace('\\', '/', $input);
|
||||
}
|
||||
|
||||
$pb->add($input);
|
||||
file_put_contents($input, $asset->getContent());
|
||||
|
||||
// output
|
||||
$output = $tempName.'.css';
|
||||
|
||||
if ($this->homeEnv) {
|
||||
// it's not really usefull but... https://github.com/chriseppstein/compass/issues/376
|
||||
$pb->setEnv('HOME', FilesystemUtils::getTemporaryDirectory());
|
||||
$this->mergeEnv($pb);
|
||||
}
|
||||
|
||||
$proc = $pb->getProcess();
|
||||
$code = $proc->run();
|
||||
|
||||
if (0 !== $code) {
|
||||
unlink($input);
|
||||
if (isset($configFile)) {
|
||||
unlink($configFile);
|
||||
}
|
||||
|
||||
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
|
||||
}
|
||||
|
||||
$asset->setContent(file_get_contents($output));
|
||||
|
||||
unlink($input);
|
||||
unlink($output);
|
||||
if (isset($configFile)) {
|
||||
unlink($configFile);
|
||||
}
|
||||
}
|
||||
|
||||
public function filterDump(AssetInterface $asset)
|
||||
{
|
||||
}
|
||||
|
||||
private function formatArrayToRuby($array)
|
||||
{
|
||||
$output = array();
|
||||
|
||||
// does we have an associative array ?
|
||||
if (count(array_filter(array_keys($array), "is_numeric")) != count($array)) {
|
||||
foreach ($array as $name => $value) {
|
||||
$output[] = sprintf(' :%s => "%s"', $name, addcslashes($value, '\\'));
|
||||
}
|
||||
$output = "{\n".implode(",\n", $output)."\n}";
|
||||
} else {
|
||||
foreach ($array as $name => $value) {
|
||||
$output[] = sprintf(' "%s"', addcslashes($value, '\\'));
|
||||
}
|
||||
$output = "[\n".implode(",\n", $output)."\n]";
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
|
||||
/**
|
||||
* Class CssCacheBustingFilter
|
||||
*
|
||||
* @package Assetic\Filter
|
||||
* @author Maximilian Reichel <info@phramz.com>
|
||||
*/
|
||||
class CssCacheBustingFilter extends BaseCssFilter
|
||||
{
|
||||
private $version;
|
||||
private $format = '%s?%s';
|
||||
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
public function setFormat($versionFormat)
|
||||
{
|
||||
$this->format = $versionFormat;
|
||||
}
|
||||
|
||||
public function filterLoad(AssetInterface $asset)
|
||||
{
|
||||
}
|
||||
|
||||
public function filterDump(AssetInterface $asset)
|
||||
{
|
||||
if (!$this->version) {
|
||||
return;
|
||||
}
|
||||
|
||||
$version = $this->version;
|
||||
$format = $this->format;
|
||||
|
||||
$asset->setContent($this->filterReferences(
|
||||
$asset->getContent(),
|
||||
function ($matches) use ($version, $format) {
|
||||
if (0 === strpos($matches['url'], 'data:')) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
return str_replace(
|
||||
$matches['url'],
|
||||
sprintf($format, $matches['url'], $version),
|
||||
$matches[0]
|
||||
);
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2014 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Filter;
|
||||
|
||||
use Assetic\Asset\AssetInterface;
|
||||
use Assetic\Exception\FilterException;
|
||||
use Assetic\Factory\AssetFactory;
|
||||
use Assetic\Util\FilesystemUtils;
|
||||
|
||||
/**
|
||||
* CSSEmbed filter
|
||||
*
|
||||
* @link https://github.com/nzakas/cssembed
|
||||
* @author Maxime Thirouin <maxime.thirouin@gmail.com>
|
||||
*/
|
||||
class CssEmbedFilter extends BaseProcessFilter implements DependencyExtractorInterface
|
||||
{
|
||||
private $jarPath;
|
||||
private $javaPath;
|
||||
private $charset;
|
||||
private $mhtml; // Enable MHTML mode.
|
||||
private $mhtmlRoot; // Use <root> as the MHTML root for the file.
|
||||
private $root; // Prepends <root> to all relative URLs.
|
||||
private $skipMissing; // Don't throw an error for missing image files.
|
||||
private $maxUriLength; // Maximum length for a data URI. Defaults to 32768.
|
||||
private $maxImageSize; // Maximum image size (in bytes) to convert.
|
||||
|
||||
public function __construct($jarPath, $javaPath = '/usr/bin/java')
|
||||
{
|
||||
$this->jarPath = $jarPath;
|
||||
$this->javaPath = $javaPath;
|
||||
}
|
||||
|
||||
public function setCharset($charset)
|
||||
{
|
||||
$this->charset = $charset;
|
||||
}
|
||||
|
||||
public function setMhtml($mhtml)
|
||||
{
|
||||
$this->mhtml = $mhtml;
|
||||
}
|
||||
|
||||
public function setMhtmlRoot($mhtmlRoot)
|
||||
{
|
||||
$this->mhtmlRoot = $mhtmlRoot;
|
||||
}
|
||||
|
||||
public function setRoot($root)
|
||||
{
|
||||
$this->root = $root;
|
||||
}
|
||||
|
||||
public function setSkipMissing($skipMissing)
|
||||
{
|
||||
$this->skipMissing = $skipMissing;
|
||||
}
|
||||
|
||||
public function setMaxUriLength($maxUriLength)
|
||||
{
|
||||
$this->maxUriLength = $maxUriLength;
|
||||
}
|
||||
|
||||
public function setMaxImageSize($maxImageSize)
|
||||
{
|
||||
$this->maxImageSize = $maxImageSize;
|
||||
}
|
||||
|
||||
public function filterLoad(AssetInterface $asset)
|
||||
{
|
||||
}
|
||||
|
||||
public function filterDump(AssetInterface $asset)
|
||||
{
|
||||
$pb = $this->createProcessBuilder(array(
|
||||
$this->javaPath,
|
||||
'-jar',
|
||||
$this->jarPath,
|
||||
));
|
||||
|
||||
if (null !== $this->charset) {
|
||||
$pb->add('--charset')->add($this->charset);
|
||||
}
|
||||
|
||||
if ($this->mhtml) {
|
||||
$pb->add('--mhtml');
|
||||
}
|
||||
|
||||
if (null !== $this->mhtmlRoot) {
|
||||
$pb->add('--mhtmlroot')->add($this->mhtmlRoot);
|
||||
}
|
||||
|
||||
// automatically define root if not already defined
|
||||
if (null === $this->root) {
|
||||
if ($dir = $asset->getSourceDirectory()) {
|
||||
$pb->add('--root')->add($dir);
|
||||
}
|
||||
} else {
|
||||
$pb->add('--root')->add($this->root);
|
||||
}
|
||||
|
||||
if ($this->skipMissing) {
|
||||
$pb->add('--skip-missing');
|
||||
}
|
||||
|
||||
if (null !== $this->maxUriLength) {
|
||||
$pb->add('--max-uri-length')->add($this->maxUriLength);
|
||||
}
|
||||
|
||||
if (null !== $this->maxImageSize) {
|
||||
$pb->add('--max-image-size')->add($this->maxImageSize);
|
||||
}
|
||||
|
||||
// input
|
||||
$pb->add($input = FilesystemUtils::createTemporaryFile('cssembed'));
|
||||
file_put_contents($input, $asset->getContent());
|
||||
|
||||
$proc = $pb->getProcess();
|
||||
$code = $proc->run();
|
||||
unlink($input);
|
||||
|
||||
if (0 !== $code) {
|
||||
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
|
||||
}
|
||||
|
||||
$asset->setContent($proc->getOutput());
|
||||
}
|
||||
|
||||
public function getChildren(AssetFactory $factory, $content, $loadPath = null)
|
||||
{
|
||||
// todo
|
||||
return array();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user