diff options
author | Yilun Chong <yilunchong@google.com> | 2018-07-16 13:53:22 -0700 |
---|---|---|
committer | Yilun Chong <yilunchong@google.com> | 2018-07-16 13:53:22 -0700 |
commit | 7f57d13c22356b491099a2884caf23a9cf672df3 (patch) | |
tree | 40e527ba8d2472b06e62b33a57efd2f5cb99a55d /benchmarks/php/autoload.php | |
parent | 3d603f481ed142d0be5e8e4dd6d1cb4457a51405 (diff) | |
download | protobuf-7f57d13c22356b491099a2884caf23a9cf672df3.tar.gz protobuf-7f57d13c22356b491099a2884caf23a9cf672df3.tar.bz2 protobuf-7f57d13c22356b491099a2884caf23a9cf672df3.zip |
add php benchmark
Diffstat (limited to 'benchmarks/php/autoload.php')
-rw-r--r-- | benchmarks/php/autoload.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/benchmarks/php/autoload.php b/benchmarks/php/autoload.php new file mode 100644 index 00000000..52a8741f --- /dev/null +++ b/benchmarks/php/autoload.php @@ -0,0 +1,25 @@ +<?php + +define("GOOGLE_INTERNAL_NAMESPACE", "Google\\Protobuf\\Internal\\"); +define("GOOGLE_NAMESPACE", "Google\\Protobuf\\"); +define("GOOGLE_GPBMETADATA_NAMESPACE", "GPBMetadata\\Google\\Protobuf\\"); +define("BENCHMARK_NAMESPACE", "Benchmarks"); +define("BENCHMARK_GPBMETADATA_NAMESPACE", "GPBMetadata\\Benchmarks"); + +function protobuf_autoloader_impl($class, $prefix, $include_path) { + $length = strlen($prefix); + if ((substr($class, 0, $length) === $prefix)) { + $path = $include_path . '/' . implode('/', array_map('ucwords', explode('\\', $class))) . '.php'; + include_once $path; + } +} + +function protobuf_autoloader($class) { + protobuf_autoloader_impl($class, GOOGLE_INTERNAL_NAMESPACE, getenv('PROTOBUF_PHP_SRCDIR')); + protobuf_autoloader_impl($class, GOOGLE_NAMESPACE, getenv('PROTOBUF_PHP_SRCDIR')); + protobuf_autoloader_impl($class, GOOGLE_GPBMETADATA_NAMESPACE, getenv('PROTOBUF_PHP_SRCDIR')); + protobuf_autoloader_impl($class, BENCHMARK_NAMESPACE, getenv('CURRENT_DIR')); + protobuf_autoloader_impl($class, BENCHMARK_GPBMETADATA_NAMESPACE, getenv('CURRENT_DIR')); +} + +spl_autoload_register('protobuf_autoloader'); |