Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
77.78% |
7 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
Autoloader | |
77.78% |
7 / 9 |
|
50.00% |
1 / 2 |
6.40 | |
0.00% |
0 / 1 |
register | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
autoload | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
5.39 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
4 | * presentations documents. |
5 | * |
6 | * PHPPresentation is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPPresentation |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpPresentation; |
21 | |
22 | /** |
23 | * Autoloader. |
24 | */ |
25 | class Autoloader |
26 | { |
27 | /** @const string */ |
28 | public const NAMESPACE_PREFIX = 'PhpOffice\\PhpPresentation\\'; |
29 | |
30 | /** |
31 | * Register. |
32 | */ |
33 | public static function register(): void |
34 | { |
35 | spl_autoload_register([new self(), 'autoload']); |
36 | } |
37 | |
38 | /** |
39 | * Autoload. |
40 | */ |
41 | public static function autoload(string $class): void |
42 | { |
43 | $prefixLength = strlen(self::NAMESPACE_PREFIX); |
44 | if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) { |
45 | $file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength)); |
46 | $file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php'); |
47 | if (!$file) { |
48 | return; |
49 | } |
50 | if (file_exists($file)) { |
51 | /** @noinspection PhpIncludeInspection Dynamic includes */ |
52 | require_once $file; |
53 | } |
54 | } |
55 | } |
56 | } |