autoload.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. // For older (pre-2.7.2) verions of google/apiclient
  3. if (
  4. file_exists(__DIR__ . '/../apiclient/src/Google/Client.php')
  5. && !class_exists('Google_Client', false)
  6. ) {
  7. require_once(__DIR__ . '/../apiclient/src/Google/Client.php');
  8. if (
  9. defined('Google_Client::LIBVER')
  10. && version_compare(Google_Client::LIBVER, '2.7.2', '<=')
  11. ) {
  12. $servicesClassMap = [
  13. 'Google\\Client' => 'Google_Client',
  14. 'Google\\Service' => 'Google_Service',
  15. 'Google\\Service\\Resource' => 'Google_Service_Resource',
  16. 'Google\\Model' => 'Google_Model',
  17. 'Google\\Collection' => 'Google_Collection',
  18. ];
  19. foreach ($servicesClassMap as $alias => $class) {
  20. class_alias($class, $alias);
  21. }
  22. }
  23. }
  24. spl_autoload_register(function ($class) {
  25. if (0 === strpos($class, 'Google_Service_')) {
  26. // Autoload the new class, which will also create an alias for the
  27. // old class by changing underscores to namespaces:
  28. // Google_Service_Speech_Resource_Operations
  29. // => Google\Service\Speech\Resource\Operations
  30. $classExists = class_exists($newClass = str_replace('_', '\\', $class));
  31. if ($classExists) {
  32. return true;
  33. }
  34. }
  35. }, true, true);