| Conditions | 9 |
| Paths | 9 |
| Total Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | public static function onRegistration( array $credits ) { |
||
|
|
|||
| 8 | if ( defined( 'Maps_VERSION' ) ) { |
||
| 9 | // Do not initialize more than once. |
||
| 10 | return true; |
||
| 11 | } |
||
| 12 | |||
| 13 | if ( !defined( 'Maps_SETTINGS_LOADED' ) ) { |
||
| 14 | foreach ( include __DIR__ . '/DefaultSettings.php' as $key => $value ) { |
||
| 15 | $GLOBALS[$key] = $value; |
||
| 16 | } |
||
| 17 | |||
| 18 | define( 'Maps_SETTINGS_LOADED', true ); |
||
| 19 | } |
||
| 20 | |||
| 21 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
| 22 | include_once( __DIR__ . '/vendor/autoload.php' ); |
||
| 23 | } |
||
| 24 | |||
| 25 | define( 'Maps_VERSION', $credits['version'] ); |
||
| 26 | define( 'SM_VERSION', Maps_VERSION ); |
||
| 27 | |||
| 28 | if ( !(bool)'Defining PHP constants in JSON is a bad idea and breaks tools' ) { |
||
| 29 | define( 'NS_GEO_JSON', 420 ); |
||
| 30 | define( 'NS_GEO_JSON_TALK', 421 ); |
||
| 31 | } |
||
| 32 | |||
| 33 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
| 34 | if ( $GLOBALS['egMapsDisableExtension'] ) { |
||
| 35 | return true; |
||
| 36 | } |
||
| 37 | |||
| 38 | // Only initialize the extension when all dependencies are present. |
||
| 39 | if ( !defined( 'Validator_VERSION' ) ) { |
||
| 40 | throw new Exception( 'You need to have Validator installed in order to use Maps' ); |
||
| 41 | } |
||
| 42 | |||
| 43 | if ( version_compare( $GLOBALS['wgVersion'], '1.27c', '<' ) ) { |
||
| 44 | throw new Exception( |
||
| 45 | 'This version of Maps requires MediaWiki 1.27 or above; use Maps 4.2.x for older versions.' |
||
| 46 | . ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md' |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | ( new MapsSetup( $GLOBALS ) )->setup(); |
||
| 51 | |||
| 52 | return true; |
||
| 53 | }; |
||
| 54 | |||
| 55 | return true; |
||
| 56 | } |
||
| 57 | |||
| 62 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: