-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathleaflet-php-loader.php
49 lines (40 loc) · 1.47 KB
/
leaflet-php-loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* This file is the loader for the LeafletPHP class.
*
* @package LeafletPHP
*/
$version = '0.0.3';
if ( !class_exists( 'leafletphp_loader' ) ) {
/**
* A small simple loader class. It collects all instances of LeafletPHP, then loads one of them.
*/
class leafletphp_loader {
public static $versions = array();
// All instances call this static function to load in their verions and files.
public static function register_version($version_number,$file) {
leafletphp_loader::$versions[$version_number] = $file;
}
/**
* A loader function for apl_autoload_register.
*
* This gets called by PHP if LeafletPHP is not a class.
*
* This is preferable to always loading the class, since
* this will avoid loading it if it's not needed.
*/
public static function load( $className ){
if ( $className === 'LeafletPHP' ) {
// Sort keys by version_compare.
uksort( leafletphp_loader::$versions, 'version_compare' );
// Go to the end of the array and require the file.
require_once( end( leafletphp_loader::$versions ) );
// Set the $version variable. Means we only have to keep the version in one place (each individual install's loader file).
LeafletPHP::$version = key( leafletphp_loader::$versions );
}
}
}
// Let PHP auto loading only include the file if needed
spl_autoload_register( array( 'leafletphp_loader','load' ) );
}
leafletphp_loader::register_version($version,dirname( __FILE__ ) . '/leaflet-php.php' );