| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 1 | <?php | 
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 2 | /* | 
 | 3 |  * Licensed to the Apache Software Foundation (ASF) under one | 
 | 4 |  * or more contributor license agreements. See the NOTICE file | 
 | 5 |  * distributed with this work for additional information | 
 | 6 |  * regarding copyright ownership. The ASF licenses this file | 
 | 7 |  * to you under the Apache License, Version 2.0 (the | 
 | 8 |  * "License"); you may not use this file except in compliance | 
 | 9 |  * with the License. You may obtain a copy of the License at | 
| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 10 |  * | 
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 11 |  *   http://www.apache.org/licenses/LICENSE-2.0 | 
 | 12 |  * | 
 | 13 |  * Unless required by applicable law or agreed to in writing, | 
 | 14 |  * software distributed under the License is distributed on an | 
 | 15 |  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
 | 16 |  * KIND, either express or implied. See the License for the | 
 | 17 |  * specific language governing permissions and limitations | 
 | 18 |  * under the License. | 
| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 19 |  * | 
 | 20 |  * @package thrift | 
| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 21 |  */ | 
 | 22 |  | 
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 23 |  | 
| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 24 | /** | 
 | 25 |  * Include this file if you wish to use autoload with your PHP generated Thrift | 
 | 26 |  * code. The generated code will *not* include any defined Thrift classes by | 
 | 27 |  * default, except for the service interfaces. The generated code will populate | 
 | 28 |  * values into $GLOBALS['THRIFT_AUTOLOAD'] which can be used by the autoload | 
| Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 29 |  * method below. If you have your own autoload system already in place, rename your | 
 | 30 |  * __autoload function to something else and then do: | 
 | 31 |  * $GLOBALS['AUTOLOAD_HOOKS'][] = 'my_autoload_func'; | 
| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 32 |  * | 
| David Reiss | a9ea68b | 2009-02-17 20:28:24 +0000 | [diff] [blame] | 33 |  * Generate this code using the --gen php:autoload Thrift generator flag. | 
| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 34 |  */ | 
 | 35 |  | 
 | 36 | $GLOBALS['THRIFT_AUTOLOAD'] = array(); | 
| Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 37 | $GLOBALS['AUTOLOAD_HOOKS'] = array(); | 
| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 38 |  | 
 | 39 | if (!function_exists('__autoload')) { | 
 | 40 |   function __autoload($class) { | 
 | 41 |     global $THRIFT_AUTOLOAD; | 
| Mark Slee | d0f5b28 | 2007-11-28 04:29:25 +0000 | [diff] [blame] | 42 |     $classl = strtolower($class); | 
| Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 43 |     if (isset($THRIFT_AUTOLOAD[$classl])) { | 
 | 44 |       include_once $GLOBALS['THRIFT_ROOT'].'/packages/'.$THRIFT_AUTOLOAD[$classl]; | 
 | 45 |     } else if (!empty($GLOBALS['AUTOLOAD_HOOKS'])) { | 
 | 46 |       foreach ($GLOBALS['AUTOLOAD_HOOKS'] as $hook) { | 
 | 47 |         $hook($class); | 
 | 48 |       } | 
| Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 49 |     } | 
 | 50 |   } | 
 | 51 | } |