-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautoload.php
More file actions
84 lines (75 loc) · 2.89 KB
/
autoload.php
File metadata and controls
84 lines (75 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php declare(strict_types=1);
/**
* This file is part of the PHP_CompatInfoDB package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Laurent Laville
* @since Release 6.13.0
*/
namespace Bartlett\CompatInfoDb;
use RuntimeException;
use function basename;
use function dirname;
use function file_exists;
use function implode;
use function spl_autoload_register;
use function sprintf;
use const DIRECTORY_SEPARATOR;
if (class_exists(__NAMESPACE__ . '\Autoload', false) === false) {
class Autoload
{
/**
* The composer autoloader.
*/
private static ?\Composer\Autoload\ClassLoader $composerAutoloader = null;
public static function load(string $class): void
{
if (self::$composerAutoloader === null) {
if (isset($GLOBALS['_composer_autoload_path'])) {
$possibleAutoloadPaths = [
dirname($GLOBALS['_composer_autoload_path'])
];
$autoloader = basename($GLOBALS['_composer_autoload_path']);
} else {
$possibleAutoloadPaths = [
// local dev repository
__DIR__,
// dependency
dirname(__DIR__, 3),
];
$autoloader = 'vendor/autoload.php';
}
self::$composerAutoloader = require self::getAutoloadFile($possibleAutoloadPaths, $autoloader);
$possibleAutoloadPaths = [
// local dependencies for dev
__DIR__ . '/vendor-bin/sf-framework-bundle/',
];
$autoloader = 'vendor/autoload.php';
try {
self::$composerAutoloader = require_once self::getAutoloadFile($possibleAutoloadPaths, $autoloader);
} catch (RuntimeException $e) {
// unable to find additional/optional dev deps: it's not an error
}
}
self::$composerAutoloader->loadClass($class);
}
private static function getAutoloadFile(array $possibleAutoloadPaths, string $autoloader): string
{
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);
}