MediaWiki REL1_31
benchmarkCSSMin.php
Go to the documentation of this file.
1<?php
23require_once __DIR__ . '/Benchmarker.php';
24
31 public function __construct() {
32 parent::__construct();
33 $this->addDescription( 'Benchmarks CSSMin.' );
34 $this->addOption( 'file', 'Path to CSS file (may be gzipped)', false, true );
35 $this->addOption( 'out', 'Echo output of one run to stdout for inspection', false, false );
36 }
37
38 public function execute() {
39 $file = $this->getOption( 'file', __DIR__ . '/cssmin/styles.css' );
40 $filename = basename( $file );
41 $css = $this->loadFile( $file );
42
43 if ( $this->hasOption( 'out' ) ) {
44 echo "## minify\n\n",
46 "\n\n";
47 echo "## remap\n\n",
48 CSSMin::remap( $css, dirname( $file ), 'https://example.org/test/', true ),
49 "\n";
50 return;
51 }
52
53 $this->bench( [
54 "minify ($filename)" => [
55 'function' => [ CSSMin::class, 'minify' ],
56 'args' => [ $css ]
57 ],
58 "remap ($filename)" => [
59 'function' => [ CSSMin::class, 'remap' ],
60 'args' => [ $css, dirname( $file ), 'https://example.org/test/', true ]
61 ],
62 ] );
63 }
64
65 private function loadFile( $file ) {
66 $css = file_get_contents( $file );
67 // Detect GZIP compression header
68 if ( substr( $css, 0, 2 ) === "\037\213" ) {
69 $css = gzdecode( $css );
70 }
71 return $css;
72 }
73}
74
75$maintClass = BenchmarkCSSMin::class;
76require_once RUN_MAINTENANCE_IF_MAIN;
$maintClass
Maintenance script that benchmarks CSSMin.
execute()
Do the actual work.
__construct()
Default constructor.
Base class for benchmark scripts.
bench(array $benchs)
static minify( $css)
Removes whitespace from CSS data.
Definition CSSMin.php:547
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:243
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
require_once RUN_MAINTENANCE_IF_MAIN