1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Autoloader for PhpSpreadsheet classes |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet |
9
|
|
|
* |
10
|
|
|
* This library is free software; you can redistribute it and/or |
11
|
|
|
* modify it under the terms of the GNU Lesser General Public |
12
|
|
|
* License as published by the Free Software Foundation; either |
13
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This library is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18
|
|
|
* Lesser General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Lesser General Public |
21
|
|
|
* License along with this library; if not, write to the Free Software |
22
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23
|
|
|
* |
24
|
|
|
* @category PhpSpreadsheet |
25
|
|
|
* @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
26
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
27
|
|
|
* @version ##VERSION##, ##DATE## |
28
|
|
|
*/ |
29
|
|
|
class Autoloader |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Register the Autoloader with SPL |
33
|
|
|
*/ |
34
|
|
|
public static function register() |
35
|
|
|
{ |
36
|
|
|
if (function_exists('__autoload')) { |
37
|
|
|
// Register any existing autoloader function with SPL, so we don't get any clashes |
38
|
|
|
spl_autoload_register('__autoload'); |
39
|
|
|
} |
40
|
|
|
// Register ourselves with SPL |
41
|
|
|
return spl_autoload_register([\PhpOffice\PhpSpreadsheet\Autoloader::class, 'load'], true, true); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Autoload a class identified by name |
46
|
|
|
* |
47
|
|
|
* @param string $className Name of the object to load |
48
|
|
|
*/ |
49
|
108 |
|
public static function load($className) |
50
|
|
|
{ |
51
|
108 |
|
$prefix = 'PhpOffice\\PhpSpreadsheet\\'; |
52
|
108 |
|
if ((class_exists($className, false)) || (strpos($className, $prefix) !== 0)) { |
53
|
|
|
// Either already loaded, or not a PhpSpreadsheet class request |
54
|
80 |
|
return false; |
55
|
|
|
} |
56
|
|
|
|
57
|
102 |
|
$classFilePath = __DIR__ . DIRECTORY_SEPARATOR . |
58
|
102 |
|
'PhpSpreadsheet' . DIRECTORY_SEPARATOR . |
59
|
102 |
|
str_replace([$prefix, '\\'], ['', '/'], $className) . |
60
|
102 |
|
'.php'; |
61
|
|
|
|
62
|
102 |
|
if ((file_exists($classFilePath) === false) || (is_readable($classFilePath) === false)) { |
63
|
|
|
// Can't load |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
102 |
|
require $classFilePath; |
67
|
102 |
|
} |
68
|
|
|
} |
69
|
|
|
|