blob: dc6133c38d2776e6e6d672009f513057b3f4bb20 [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
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 Sleee02ab332007-11-28 04:17:49 +000019 * 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 Slee09f69e02007-11-17 00:32:36 +000022 *
23 * Generate this code using the -phpa Thrift generator flag.
24 */
25
26$GLOBALS['THRIFT_AUTOLOAD'] = array();
Mark Sleee02ab332007-11-28 04:17:49 +000027$GLOBALS['AUTOLOAD_HOOKS'] = array();
Mark Slee09f69e02007-11-17 00:32:36 +000028
29if (!function_exists('__autoload')) {
30 function __autoload($class) {
31 global $THRIFT_AUTOLOAD;
Mark Sleed0f5b282007-11-28 04:29:25 +000032 $classl = strtolower($class);
Mark Sleee02ab332007-11-28 04:17:49 +000033 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 Slee09f69e02007-11-17 00:32:36 +000039 }
40 }
41}