Skip to content

Commit

Permalink
previous config/bootstap.php file contents are included into new auto…
Browse files Browse the repository at this point in the history
…load.php file
  • Loading branch information
llaville committed May 2, 2024
1 parent 471732a commit 97a67ed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 52 deletions.
36 changes: 34 additions & 2 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,46 @@ class Autoload
*/
private static ?\Composer\Autoload\ClassLoader $composerAutoloader = null;

public static function load(string $class)
public static function load(string $class): void
{
if (self::$composerAutoloader === null) {
self::$composerAutoloader = require __DIR__ . '/vendor/autoload.php';
self::$composerAutoloader = require self::getAutoloadFile();
}

self::$composerAutoloader->loadClass($class);
}

private static function getAutoloadFile(): string
{
if (isset($_composer_autoload_path)) {
$possibleAutoloadPaths = [
dirname($_composer_autoload_path)
];
$autoloader = basename($_composer_autoload_path);
} else {
$possibleAutoloadPaths = [
// local dev repository
__DIR__,
// dependency
dirname(__DIR__, 3),
];
$autoloader = 'vendor/autoload.php';
}

foreach ($possibleAutoloadPaths as $possibleAutoloadPath) {
if (file_exists($possibleAutoloadPath . DIRECTORY_SEPARATOR . $autoloader)) {
return $possibleAutoloadPath . DIRECTORY_SEPARATOR . $autoloader;
}
}

throw new \RuntimeException(
sprintf(
'Unable to find "%s" in "%s" paths.',
$autoloader,
implode('", "', $possibleAutoloadPaths)
)
);
}
}

spl_autoload_register(__NAMESPACE__ . '\Autoload::load', true, true);
Expand Down
50 changes: 0 additions & 50 deletions config/bootstrap.php

This file was deleted.

0 comments on commit 97a67ed

Please sign in to comment.