autoload.php 1.1 KB

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