1
+ <?php
2
+ /**
3
+ * Copyright 2014 Facebook, Inc.
4
+ *
5
+ * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
+ * use, copy, modify, and distribute this software in source code or binary
7
+ * form for use in connection with the web services and APIs provided by
8
+ * Facebook.
9
+ *
10
+ * As with any software that integrates with the Facebook platform, your use
11
+ * of this software is subject to the Facebook Developer Principles and
12
+ * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
+ * shall be included in all copies or substantial portions of the software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ * DEALINGS IN THE SOFTWARE.
22
+ *
23
+ */
24
+
25
+ /**
26
+ * You only need this file if you are not using composer.
27
+ * Why are you not using composer?
28
+ * https://getcomposer.org/
29
+ */
30
+
31
+ if (version_compare (PHP_VERSION , '5.4.0 ' , '< ' )) {
32
+ throw new Exception ('The Facebook SDK v4 requires PHP version 5.4 or higher. ' );
33
+ }
34
+
35
+ /**
36
+ * Register the autoloader for the Facebook SDK classes.
37
+ * Based off the official PSR-4 autoloader example found here:
38
+ * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
39
+ *
40
+ * @param string $class The fully-qualified class name.
41
+ * @return void
42
+ */
43
+ spl_autoload_register (function ($ class )
44
+ {
45
+ // project-specific namespace prefix
46
+ $ prefix = 'Facebook \\' ;
47
+
48
+ // base directory for the namespace prefix
49
+ $ base_dir = defined ('FACEBOOK_SDK_V4_SRC_DIR ' ) ? FACEBOOK_SDK_V4_SRC_DIR : __DIR__ . '/src/Facebook/ ' ;
50
+
51
+ // does the class use the namespace prefix?
52
+ $ len = strlen ($ prefix );
53
+ if (strncmp ($ prefix , $ class , $ len ) !== 0 ) {
54
+ // no, move to the next registered autoloader
55
+ return ;
56
+ }
57
+
58
+ // get the relative class name
59
+ $ relative_class = substr ($ class , $ len );
60
+
61
+ // replace the namespace prefix with the base directory, replace namespace
62
+ // separators with directory separators in the relative class name, append
63
+ // with .php
64
+ $ file = $ base_dir . str_replace ('\\' , '/ ' , $ relative_class ) . '.php ' ;
65
+
66
+ // if the file exists, require it
67
+ if (file_exists ($ file )) {
68
+ require $ file ;
69
+ }
70
+ });
0 commit comments