MediaWiki  master
benchmarkCSSMin.php
Go to the documentation of this file.
1 <?php
22 require_once __DIR__ . '/Benchmarker.php';
23 
30  public function __construct() {
31  parent::__construct();
32  $this->addDescription( 'Benchmarks CSSMin.' );
33  $this->addOption( 'file', 'Path to CSS file (may be gzipped)', false, true );
34  $this->addOption( 'out', 'Echo output of one run to stdout for inspection', false, false );
35  }
36 
37  public function execute() {
38  $file = $this->getOption( 'file', __DIR__ . '/cssmin/styles.css' );
39  $filename = basename( $file );
40  $css = $this->loadFile( $file );
41 
42  if ( $this->hasOption( 'out' ) ) {
43  echo "## minify\n\n",
44  CSSMin::minify( $css ),
45  "\n\n";
46  echo "## remap\n\n",
47  CSSMin::remap( $css, dirname( $file ), 'https://example.org/test/', true ),
48  "\n";
49  return;
50  }
51 
52  $this->bench( [
53  "minify ($filename)" => [
54  'function' => [ CSSMin::class, 'minify' ],
55  'args' => [ $css ]
56  ],
57  "remap ($filename)" => [
58  'function' => [ CSSMin::class, 'remap' ],
59  'args' => [ $css, dirname( $file ), 'https://example.org/test/', true ]
60  ],
61  ] );
62  }
63 }
64 
65 $maintClass = BenchmarkCSSMin::class;
66 require_once RUN_MAINTENANCE_IF_MAIN;
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
getOption( $name, $default=null)
Get an option, or return the default.
static minify( $css)
Removes whitespace from CSS data.
Definition: CSSMin.php:540
hasOption( $name)
Checks to see if a particular option exists.
static remap( $source, $local, $remote, $embedData=true)
Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an ...
Definition: CSSMin.php:239
$maintClass
bench(array $benchs)
Definition: Benchmarker.php:50
addDescription( $text)
Set the description text.
loadFile( $file)
Maintenance script that benchmarks CSSMin.
Base class for benchmark scripts.
Definition: Benchmarker.php:40
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.