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