|
5 | 5 | * Copyright © Magento, Inc. All rights reserved.
|
6 | 6 | * See COPYING.txt for license details.
|
7 | 7 | */
|
| 8 | +declare(strict_types=1); |
| 9 | + |
8 | 10 | use Magento\Framework\Autoload\AutoloaderRegistry;
|
9 | 11 | use Magento\Framework\Autoload\ClassLoaderWrapper;
|
10 | 12 |
|
11 | 13 | /**
|
12 | 14 | * Shortcut constant for the root directory
|
13 | 15 | */
|
14 |
| -define('BP', dirname(__DIR__)); |
| 16 | +\define('BP', \dirname(__DIR__)); |
15 | 17 |
|
16 |
| -define('VENDOR_PATH', BP . '/app/etc/vendor_path.php'); |
| 18 | +\define('VENDOR_PATH', BP . '/app/etc/vendor_path.php'); |
17 | 19 |
|
18 |
| -if (!file_exists(VENDOR_PATH)) { |
| 20 | +if (!\is_readable(VENDOR_PATH)) { |
19 | 21 | throw new \Exception(
|
20 | 22 | 'We can\'t read some files that are required to run the Magento application. '
|
21 | 23 | . 'This usually means file permissions are set incorrectly.'
|
22 | 24 | );
|
23 | 25 | }
|
24 | 26 |
|
25 |
| -$vendorDir = require VENDOR_PATH; |
26 |
| -$vendorAutoload = BP . "/{$vendorDir}/autoload.php"; |
| 27 | +$vendorAutoload = ( |
| 28 | + static function (): ?string { |
| 29 | + $vendorDir = require VENDOR_PATH; |
| 30 | + |
| 31 | + $vendorAutoload = BP . "/{$vendorDir}/autoload.php"; |
| 32 | + if (\is_readable($vendorAutoload)) { |
| 33 | + return $vendorAutoload; |
| 34 | + } |
| 35 | + |
| 36 | + $vendorAutoload = "{$vendorDir}/autoload.php"; |
| 37 | + if (\is_readable($vendorAutoload)) { |
| 38 | + return $vendorAutoload; |
| 39 | + } |
| 40 | + |
| 41 | + return null; |
| 42 | + } |
| 43 | +)(); |
27 | 44 |
|
28 |
| -/* 'composer install' validation */ |
29 |
| -if (file_exists($vendorAutoload)) { |
30 |
| - $composerAutoloader = include $vendorAutoload; |
31 |
| -} else if (file_exists("{$vendorDir}/autoload.php")) { |
32 |
| - $vendorAutoload = "{$vendorDir}/autoload.php"; |
33 |
| - $composerAutoloader = include $vendorAutoload; |
34 |
| -} else { |
| 45 | +if ($vendorAutoload === null) { |
35 | 46 | throw new \Exception(
|
36 | 47 | 'Vendor autoload is not found. Please run \'composer install\' under application root directory.'
|
37 | 48 | );
|
38 | 49 | }
|
39 | 50 |
|
| 51 | +$composerAutoloader = include $vendorAutoload; |
40 | 52 | AutoloaderRegistry::registerAutoloader(new ClassLoaderWrapper($composerAutoloader));
|
0 commit comments