blob: 6c6026f5a3ba46609078c3d4106704ffdafaca81 [file] [log] [blame]
Mark Slee09f69e02007-11-17 00:32:36 +00001<?php
2
3/**
4 * Copyright (c) 2006- Facebook
5 * Distributed under the Thrift Software License
6 *
7 * See accompanying file LICENSE or visit the Thrift site at:
8 * http://developers.facebook.com/thrift/
9 *
10 * @package thrift
Mark Slee09f69e02007-11-17 00:32:36 +000011 */
12
13/**
14 * Include this file if you wish to use autoload with your PHP generated Thrift
15 * code. The generated code will *not* include any defined Thrift classes by
16 * default, except for the service interfaces. The generated code will populate
17 * values into $GLOBALS['THRIFT_AUTOLOAD'] which can be used by the autoload
Mark Sleee02ab332007-11-28 04:17:49 +000018 * method below. If you have your own autoload system already in place, rename your
19 * __autoload function to something else and then do:
20 * $GLOBALS['AUTOLOAD_HOOKS'][] = 'my_autoload_func';
Mark Slee09f69e02007-11-17 00:32:36 +000021 *
David Reissa9ea68b2009-02-17 20:28:24 +000022 * Generate this code using the --gen php:autoload Thrift generator flag.
Mark Slee09f69e02007-11-17 00:32:36 +000023 */
24
25$GLOBALS['THRIFT_AUTOLOAD'] = array();
Mark Sleee02ab332007-11-28 04:17:49 +000026$GLOBALS['AUTOLOAD_HOOKS'] = array();
Mark Slee09f69e02007-11-17 00:32:36 +000027
28if (!function_exists('__autoload')) {
29 function __autoload($class) {
30 global $THRIFT_AUTOLOAD;
Mark Sleed0f5b282007-11-28 04:29:25 +000031 $classl = strtolower($class);
Mark Sleee02ab332007-11-28 04:17:49 +000032 if (isset($THRIFT_AUTOLOAD[$classl])) {
33 include_once $GLOBALS['THRIFT_ROOT'].'/packages/'.$THRIFT_AUTOLOAD[$classl];
34 } else if (!empty($GLOBALS['AUTOLOAD_HOOKS'])) {
35 foreach ($GLOBALS['AUTOLOAD_HOOKS'] as $hook) {
36 $hook($class);
37 }
Mark Slee09f69e02007-11-17 00:32:36 +000038 }
39 }
40}