1
+ <?php
2
+
3
+ /**
4
+ * You only need this file if you are not using composer.
5
+ */
6
+
7
+ if (version_compare (PHP_VERSION , '5.4.0 ' , '< ' )) {
8
+ throw new Exception ('The Parse SDK requires PHP version 5.4 or higher. ' );
9
+ }
10
+
11
+ /**
12
+ * Register the autoloader for the Parse SDK
13
+ * Based off the official PSR-4 autoloader example found here:
14
+ * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
15
+ *
16
+ * @param string $class The fully-qualified class name.
17
+ * @return void
18
+ */
19
+ spl_autoload_register (function ($ class )
20
+ {
21
+ // Parse class prefix
22
+ $ prefix = 'Parse \\' ;
23
+
24
+ // base directory for the namespace prefix
25
+ $ base_dir = defined ('PARSE_SDK_DIR ' ) ? PARSE_SDK_DIR : __DIR__ . '/src/Parse/ ' ;
26
+
27
+ // does the class use the namespace prefix?
28
+ $ len = strlen ( $ prefix );
29
+ if ( strncmp ($ prefix , $ class , $ len ) !== 0 ) {
30
+ // no, move to the next registered autoloader
31
+ return ;
32
+ }
33
+
34
+ // get the relative class name
35
+ $ relative_class = substr ( $ class , $ len );
36
+
37
+ // replace the namespace prefix with the base directory, replace namespace
38
+ // separators with directory separators in the relative class name, append
39
+ // with .php
40
+ $ file = $ base_dir . str_replace ( '\\' , '/ ' , $ relative_class ) . '.php ' ;
41
+
42
+ // echo $relative_class . '<br/>';
43
+
44
+ // if the file exists, require it
45
+ if ( file_exists ( $ file ) ) {
46
+ require $ file ;
47
+ }
48
+ });
0 commit comments