-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautoloader.php
More file actions
51 lines (42 loc) · 1.18 KB
/
Copy pathautoloader.php
File metadata and controls
51 lines (42 loc) · 1.18 KB
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
50
51
<?php
/**
* Autoloader for PHP classes of this plugin
*
* @author Amit Gupta <http://amitgupta.in/>
*/
/*
* Register resource autoloader
*/
spl_autoload_register( 'ig_syntax_hiliter_autoloader' );
/**
* The function that makes on-demand autoloading of files for this plugin
* possible. It is registered with spl_autoload_register() and must not be
* called directly.
*
* @param string $resource Fully qualified name of the resource that is to be loaded
* @return void
*/
function ig_syntax_hiliter_autoloader( $resource = '' ) {
$namespace_root = 'iG\Syntax_Hiliter';
$resource = trim( $resource, '\\' );
if ( empty( $resource ) || strpos( $resource, '\\' ) === false || strpos( $resource, $namespace_root ) !== 0 ) {
//not our namespace, bail out
return;
}
$path = str_replace(
'_',
'-',
implode(
'/',
array_slice( //remove the namespace root and grab the actual resource
explode( '\\', $resource ),
2
)
)
);
$path = sprintf( '%s/classes/%s.php', untrailingslashit( IG_SYNTAX_HILITER_ROOT ), strtolower( $path ) );
if ( file_exists( $path ) ) {
require_once $path;
}
}
//EOF