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 | |
| 23 | /** |
| 24 | * Include this file if you wish to use autoload with your PHP generated Thrift |
| 25 | * code. The generated code will *not* include any defined Thrift classes by |
| 26 | * default, except for the service interfaces. The generated code will populate |
| 27 | * values into $GLOBALS['THRIFT_AUTOLOAD'] which can be used by the autoload |
Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 28 | * method below. If you have your own autoload system already in place, rename your |
| 29 | * __autoload function to something else and then do: |
| 30 | * $GLOBALS['AUTOLOAD_HOOKS'][] = 'my_autoload_func'; |
Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 31 | * |
David Reiss | a9ea68b | 2009-02-17 20:28:24 +0000 | [diff] [blame] | 32 | * Generate this code using the --gen php:autoload Thrift generator flag. |
Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | $GLOBALS['THRIFT_AUTOLOAD'] = array(); |
Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 36 | $GLOBALS['AUTOLOAD_HOOKS'] = array(); |
Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 37 | |
| 38 | if (!function_exists('__autoload')) { |
Roger Thomas | 6fb5923 | 2014-11-04 10:09:23 +0000 | [diff] [blame^] | 39 | function __autoload($class) |
| 40 | { |
Mark Slee | 09f69e0 | 2007-11-17 00:32:36 +0000 | [diff] [blame] | 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]; |
Roger Thomas | 6fb5923 | 2014-11-04 10:09:23 +0000 | [diff] [blame^] | 45 | } elseif (!empty($GLOBALS['AUTOLOAD_HOOKS'])) { |
Mark Slee | e02ab33 | 2007-11-28 04:17:49 +0000 | [diff] [blame] | 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 | } |