1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The MIT License |
4
|
|
|
* |
5
|
|
|
* Copyright 2018 Peter Gee <https://github.com/pgee70>. |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in |
15
|
|
|
* all copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23
|
|
|
* THE SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
namespace i3Soft\CDA; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Autoloader |
29
|
|
|
*/ |
30
|
|
|
class Autoloader |
31
|
|
|
{ |
32
|
|
|
/** @const string */ |
33
|
|
|
const NAMESPACE_PREFIX = 'i3Soft\\CDA\\'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Register |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public static function register() |
41
|
|
|
{ |
42
|
|
|
spl_autoload_register(array(new self, 'autoload')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Autoload |
47
|
|
|
* |
48
|
|
|
* @param string $class |
49
|
|
|
*/ |
50
|
|
|
public static function autoload($class) |
51
|
|
|
{ |
52
|
|
|
$prefixLength = strlen(self::NAMESPACE_PREFIX); |
53
|
|
|
if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) { |
54
|
|
|
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength)); |
55
|
|
|
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php'); |
56
|
|
|
if (file_exists($file)) { |
57
|
|
|
/** @noinspection PhpIncludeInspection Dynamic includes */ |
58
|
|
|
require_once $file; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|