Project

General

Profile

1
<?php
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
10
 *
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.
19
 *
20
 * @package thrift
21
 */
22

    
23

    
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
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';
32
 *
33
 * Generate this code using the --gen php:autoload Thrift generator flag.
34
 */
35

    
36
$GLOBALS['THRIFT_AUTOLOAD'] = array();
37
$GLOBALS['AUTOLOAD_HOOKS'] = array();
38

    
39
if (!function_exists('__autoload')) {
40
  function __autoload($class) {
41
    global $THRIFT_AUTOLOAD;
42
    $classl = strtolower($class);
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
      }
49
    }
50
  }
51
}
(2-2/3)