• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?php
2
3define("GOOGLE_INTERNAL_NAMESPACE", "Google\\Protobuf\\Internal\\");
4define("GOOGLE_NAMESPACE", "Google\\Protobuf\\");
5define("GOOGLE_GPBMETADATA_NAMESPACE", "GPBMetadata\\Google\\Protobuf\\");
6define("BENCHMARK_NAMESPACE", "Benchmarks");
7define("BENCHMARK_GPBMETADATA_NAMESPACE", "GPBMetadata\\Benchmarks");
8
9function protobuf_autoloader_impl($class, $prefix, $include_path) {
10    $length = strlen($prefix);
11    if ((substr($class, 0, $length) === $prefix)) {
12        $path = $include_path . '/' . implode('/', array_map('ucwords', explode('\\', $class))) . '.php';
13        include_once $path;
14    }
15}
16
17function protobuf_autoloader($class) {
18    protobuf_autoloader_impl($class, GOOGLE_INTERNAL_NAMESPACE, getenv('PROTOBUF_PHP_SRCDIR'));
19    protobuf_autoloader_impl($class, GOOGLE_NAMESPACE, getenv('PROTOBUF_PHP_SRCDIR'));
20    protobuf_autoloader_impl($class, GOOGLE_GPBMETADATA_NAMESPACE, getenv('PROTOBUF_PHP_SRCDIR'));
21    protobuf_autoloader_impl($class, BENCHMARK_NAMESPACE, getenv('CURRENT_DIR'));
22    protobuf_autoloader_impl($class, BENCHMARK_GPBMETADATA_NAMESPACE, getenv('CURRENT_DIR'));
23}
24
25spl_autoload_register('protobuf_autoloader');
26