bootstrap.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php declare(strict_types=1);
  2. /**
  3. * This file is part of toolkit/stdlib.
  4. *
  5. * @author https://github.com/inhere
  6. * @link https://github.com/php-toolkit/stdlib
  7. * @license MIT
  8. */
  9. error_reporting(E_ALL | E_STRICT);
  10. date_default_timezone_set('Asia/Shanghai');
  11. spl_autoload_register(static function ($class): void {
  12. $file = '';
  13. if (str_starts_with($class, 'Toolkit\Stdlib\Example\\')) {
  14. $path = str_replace('\\', '/', substr($class, strlen('Toolkit\Stdlib\Example\\')));
  15. $file = dirname(__DIR__) . "/example/$path.php";
  16. } elseif (str_starts_with($class, 'Toolkit\StdlibTest\\')) {
  17. $path = str_replace('\\', '/', substr($class, strlen('Toolkit\StdlibTest\\')));
  18. $file = __DIR__ . "/$path.php";
  19. } elseif (str_starts_with($class, 'Toolkit\Stdlib\\')) {
  20. $path = str_replace('\\', '/', substr($class, strlen('Toolkit\Stdlib\\')));
  21. $file = dirname(__DIR__) . "/src/$path.php";
  22. }
  23. if ($file && is_file($file)) {
  24. include $file;
  25. }
  26. });
  27. if (is_file(dirname(__DIR__, 3) . '/autoload.php')) {
  28. require dirname(__DIR__, 3) . '/autoload.php';
  29. } elseif (is_file(dirname(__DIR__) . '/vendor/autoload.php')) {
  30. require dirname(__DIR__) . '/vendor/autoload.php';
  31. }