1
1
<?php
2
2
/**
3
- * PHPProject
4
- *
5
- * Copyright (c) 2012 - 2012 PHPProject
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPProject
22
- * @package PHPProject
23
- * @copyright Copyright (c) 2012 - 2012 PHPProject (https://github.com/PHPOffice/PHPProject)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version ##VERSION##, ##DATE##
26
- */
27
-
28
- PHPProject_Autoloader::Register ();
29
- // check mbstring.func_overload
30
- if (ini_get ('mbstring.func_overload ' ) & 2 ) {
31
- throw new Exception ('Multibyte function overloading in PHP must be disabled for string functions (2). ' );
32
- }
33
-
3
+ * This file is part of PHPProject - A pure PHP library for reading and writing
4
+ * presentations documents.
5
+ *
6
+ * PHPProject 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/PHPWord/contributors.
12
+ *
13
+ * @link https://github.com/PHPOffice/PHPProject
14
+ * @copyright 2009-2014 PHPProject contributors
15
+ * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
+ */
17
+
18
+ namespace PhpOffice \PhpProject ;
34
19
35
20
/**
36
- * PHPProject_Autoloader
37
- *
38
- * @category PHPProject
39
- * @package PHPProject
40
- * @copyright Copyright (c) 2006 - 2012 PHPProject (https://github.com/Progi1984/PHPProject)
21
+ * Autoloader
41
22
*/
42
- class PHPProject_Autoloader
23
+ class Autoloader
43
24
{
25
+ /** @const string */
26
+ const NAMESPACE_PREFIX = 'PhpOffice \\PhpProject \\' ;
27
+
44
28
/**
45
- * Register the Autoloader with SPL
29
+ * Register
46
30
*
31
+ * @return void
47
32
*/
48
- public static function Register () {
49
- if (function_exists ('__autoload ' )) {
50
- // Register any existing autoloader function with SPL, so we don't get any clashes
51
- spl_autoload_register ('__autoload ' );
52
- }
53
- // Register ourselves with SPL
54
- return spl_autoload_register (array ('PHPProject_Autoloader ' , 'Load ' ));
55
- } // function Register()
56
-
33
+ public static function register ()
34
+ {
35
+ spl_autoload_register (array (new self , 'autoload ' ));
36
+ }
57
37
58
38
/**
59
- * Autoload a class identified by name
39
+ * Autoload
60
40
*
61
- * @param string $pClassName Name of the object to load
41
+ * @param string $class
62
42
*/
63
- public static function Load ($ pClassName ){
64
- if ((class_exists ($ pClassName )) || (strpos ($ pClassName , 'PHPProject ' ) !== 0 )) {
65
- // Either already loaded, or not a PHPProject class request
66
- return FALSE ;
43
+ public static function autoload ($ class )
44
+ {
45
+ $ prefixLength = strlen (self ::NAMESPACE_PREFIX );
46
+ if (0 === strncmp (self ::NAMESPACE_PREFIX , $ class , $ prefixLength )) {
47
+ $ file = str_replace ('\\' , DIRECTORY_SEPARATOR , substr ($ class , $ prefixLength ));
48
+ $ file = realpath (__DIR__ . (empty ($ file ) ? '' : DIRECTORY_SEPARATOR ) . $ file . '.php ' );
49
+ if (file_exists ($ file )) {
50
+ /** @noinspection PhpIncludeInspection Dynamic includes */
51
+ require_once $ file ;
52
+ }
67
53
}
68
-
69
- $ pClassFilePath = PHPPROJECT_ROOT .
70
- str_replace ('_ ' ,DIRECTORY_SEPARATOR ,$ pClassName ) .
71
- '.php ' ;
72
-
73
- if ((file_exists ($ pClassFilePath ) === false ) || (is_readable ($ pClassFilePath ) === false )) {
74
- // Can't load
75
- return FALSE ;
76
- }
77
-
78
- require ($ pClassFilePath );
79
- } // function Load()
80
-
81
- }
54
+ }
55
+ }
0 commit comments