| 1 |
#!/usr/bin/php |
| 2 |
<?php |
| 3 |
|
| 4 |
die('Must be rewritten for new API'); |
| 5 |
|
| 6 |
require __DIR__ . '/../../bootstrap.php'; |
| 7 |
|
| 8 |
$cli = new MrClay\Cli; |
| 9 |
|
| 10 |
$cli->addRequiredArg('d')->assertDir()->setDescription('Your webserver\'s DOCUMENT_ROOT: Relative paths will be rewritten relative to this path.'); |
| 11 |
|
| 12 |
$cli->addOptionalArg('o')->useAsOutfile()->setDescription('Outfile: If given, output will be placed in this file.'); |
| 13 |
|
| 14 |
$cli->addOptionalArg('t')->setDescription('Test run: Return output followed by rewriting algorithm.'); |
| 15 |
|
| 16 |
if (! $cli->validate()) { |
| 17 |
echo "USAGE: ./rewrite-uris.php [-t] -d DOC_ROOT [-o OUTFILE] file ...\n"; |
| 18 |
if ($cli->isHelpRequest) { |
| 19 |
echo $cli->getArgumentsListing(); |
| 20 |
} |
| 21 |
echo "EXAMPLE: ./rewrite-uris.php -v -d../.. ../../tests/_test_files/css/paths_rewrite.css ../../tests/_test_files/css/comments.css |
| 22 |
\n"; |
| 23 |
exit(0); |
| 24 |
} |
| 25 |
|
| 26 |
$outfile = $cli->values['o']; |
| 27 |
$testRun = $cli->values['t']; |
| 28 |
$docRoot = $cli->values['d']; |
| 29 |
|
| 30 |
$pathRewriter = function ($css, $options) { |
| 31 |
return Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $options['docRoot']); |
| 32 |
}; |
| 33 |
|
| 34 |
$paths = $cli->getPathArgs(); |
| 35 |
|
| 36 |
$sources = array(); |
| 37 |
foreach ($paths as $path) { |
| 38 |
if (is_file($path)) { |
| 39 |
$sources[] = new Minify_Source(array( |
| 40 |
'filepath' => $path, |
| 41 |
'minifier' => $pathRewriter, |
| 42 |
'minifyOptions' => array('docRoot' => $docRoot), |
| 43 |
)); |
| 44 |
} else { |
| 45 |
$sources[] = new Minify_Source(array( |
| 46 |
'id' => $path, |
| 47 |
'content' => "/*** $path not found ***/\n", |
| 48 |
'minifier' => 'Minify::nullMinifier', |
| 49 |
)); |
| 50 |
} |
| 51 |
} |
| 52 |
$combined = Minify::combine($sources) . "\n"; |
| 53 |
|
| 54 |
if ($testRun) { |
| 55 |
echo $combined; |
| 56 |
echo Minify_CSS_UriRewriter::$debugText . "\n"; |
| 57 |
} else { |
| 58 |
$fp = $cli->openOutput(); |
| 59 |
fwrite($fp, $combined); |
| 60 |
$cli->closeOutput(); |
| 61 |
} |
| 62 |
|