blob: 85bd797a3be26e9d40fd464ded13700978f0c4d7 [file] [log] [blame]
Mark Slee09f69e02007-11-17 00:32:36 +00001<?php
David Reissea2cba82009-03-30 21:35:00 +00002/*
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 Slee09f69e02007-11-17 00:32:36 +000010 *
David Reissea2cba82009-03-30 21:35:00 +000011 * 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 Slee09f69e02007-11-17 00:32:36 +000019 *
20 * @package thrift
Mark Slee09f69e02007-11-17 00:32:36 +000021 */
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 Sleee02ab332007-11-28 04:17:49 +000028 * 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 Slee09f69e02007-11-17 00:32:36 +000031 *
David Reissa9ea68b2009-02-17 20:28:24 +000032 * Generate this code using the --gen php:autoload Thrift generator flag.
Mark Slee09f69e02007-11-17 00:32:36 +000033 */
34
35$GLOBALS['THRIFT_AUTOLOAD'] = array();
Mark Sleee02ab332007-11-28 04:17:49 +000036$GLOBALS['AUTOLOAD_HOOKS'] = array();
Mark Slee09f69e02007-11-17 00:32:36 +000037
38if (!function_exists('__autoload')) {
Roger Thomas6fb59232014-11-04 10:09:23 +000039 function __autoload($class)
40 {
Mark Slee09f69e02007-11-17 00:32:36 +000041 global $THRIFT_AUTOLOAD;
Mark Sleed0f5b282007-11-28 04:29:25 +000042 $classl = strtolower($class);
Mark Sleee02ab332007-11-28 04:17:49 +000043 if (isset($THRIFT_AUTOLOAD[$classl])) {
44 include_once $GLOBALS['THRIFT_ROOT'].'/packages/'.$THRIFT_AUTOLOAD[$classl];
Roger Thomas6fb59232014-11-04 10:09:23 +000045 } elseif (!empty($GLOBALS['AUTOLOAD_HOOKS'])) {
Mark Sleee02ab332007-11-28 04:17:49 +000046 foreach ($GLOBALS['AUTOLOAD_HOOKS'] as $hook) {
47 $hook($class);
48 }
Mark Slee09f69e02007-11-17 00:32:36 +000049 }
50 }
51}