Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
CRAP
81.82% covered (warning)
81.82%
9 / 11
Autoloader
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
6.22
81.82% covered (warning)
81.82%
9 / 11
 register
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 autoload
0.00% covered (danger)
0.00%
0 / 1
5.27
77.78% covered (warning)
77.78%
7 / 9
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 * @copyright   2009-2015 PHPPresentation contributors
16 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19declare(strict_types=1);
20
21namespace PhpOffice\PhpPresentation;
22
23/**
24 * Autoloader.
25 */
26class Autoloader
27{
28    /** @const string */
29    public const NAMESPACE_PREFIX = 'PhpOffice\\PhpPresentation\\';
30
31    /**
32     * Register.
33     */
34    public static function register(): void
35    {
36        spl_autoload_register([new self(), 'autoload']);
37    }
38
39    /**
40     * Autoload.
41     */
42    public static function autoload(string $class): void
43    {
44        $prefixLength = strlen(self::NAMESPACE_PREFIX);
45        if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {
46            $file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
47            $file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
48            if (!$file) {
49                return;
50            }
51            if (file_exists($file)) {
52                /** @noinspection PhpIncludeInspection Dynamic includes */
53                require_once $file;
54            }
55        }
56    }
57}