Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 1 | <?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 |
| 11 | * @author Mark Slee <mcslee@facebook.com> |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * Include this file if you wish to use autoload with your PHP generated Thrift |
| 16 | * code. The generated code will *not* include any defined Thrift classes by |
| 17 | * default, except for the service interfaces. The generated code will populate |
| 18 | * values into $GLOBALS['THRIFT_AUTOLOAD'] which can be used by the autoload |
Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 19 | * method below. If you have your own autoload system already in place, rename your |
| 20 | * __autoload function to something else and then do: |
| 21 | * $GLOBALS['AUTOLOAD_HOOKS'][] = 'my_autoload_func'; |
Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 22 | * |
| 23 | * Generate this code using the -phpa Thrift generator flag. |
| 24 | */ |
| 25 | |
| 26 | $GLOBALS['THRIFT_AUTOLOAD'] = array(); |
Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 27 | $GLOBALS['AUTOLOAD_HOOKS'] = array(); |
Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 28 | |
| 29 | if (!function_exists('__autoload')) { |
| 30 | function __autoload($class) { |
| 31 | global $THRIFT_AUTOLOAD; |
Mark Slee | d0f5b28 | 2007-11-28 04:29:25 +0000 | [diff] [blame] | 32 | $classl = strtolower($class); |
Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 33 | if (isset($THRIFT_AUTOLOAD[$classl])) { |
| 34 | include_once $GLOBALS['THRIFT_ROOT'].'/packages/'.$THRIFT_AUTOLOAD[$classl]; |
| 35 | } else if (!empty($GLOBALS['AUTOLOAD_HOOKS'])) { |
| 36 | foreach ($GLOBALS['AUTOLOAD_HOOKS'] as $hook) { |
| 37 | $hook($class); |
| 38 | } |
Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | } |