Autoloader.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. spl_autoload_register('Autoloader::autoload');
  21. /**
  22. * @deprecated See: https://github.com/aliyun/openapi-sdk-php
  23. * Class Autoloader
  24. */
  25. class Autoloader
  26. {
  27. /**
  28. * @var array
  29. */
  30. private static $autoloadPathArray = array(
  31. 'aliyun-php-sdk-core',
  32. 'aliyun-php-sdk-core/Auth',
  33. 'aliyun-php-sdk-core/Http',
  34. 'aliyun-php-sdk-core/Profile',
  35. 'aliyun-php-sdk-core/Regions',
  36. 'aliyun-php-sdk-core/Exception',
  37. );
  38. /**
  39. * Automatically find the class and load it.
  40. *
  41. * @param string $className
  42. */
  43. public static function autoload($className)
  44. {
  45. $directories = dirname(dirname(__DIR__));
  46. foreach (self::$autoloadPathArray as $path) {
  47. $file = $directories . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $className . '.php';
  48. $file = str_replace('\\', DIRECTORY_SEPARATOR, $file);
  49. if (is_file($file)) {
  50. include_once $file;
  51. break;
  52. }
  53. }
  54. }
  55. /**
  56. * Load all product folders.
  57. *
  58. * @return void
  59. */
  60. public static function loadDirectories()
  61. {
  62. $directories = dirname(dirname(__DIR__));
  63. foreach (glob($directories . DIRECTORY_SEPARATOR . '*') as $directory) {
  64. if (is_dir($directory) && basename($directory) !== 'aliyun-php-sdk-core') {
  65. self::$autoloadPathArray[] = basename($directory);
  66. }
  67. }
  68. }
  69. /**
  70. * @param string $path
  71. */
  72. public static function addAutoloadPath($path)
  73. {
  74. self::$autoloadPathArray[] = $path;
  75. }
  76. }