Skip to content

Commit

Permalink
ENGCOM-7830: improve and make more strict autoload.php #28923
Browse files Browse the repository at this point in the history
  • Loading branch information
slavvka committed Aug 14, 2020
2 parents fd48b47 + ced4144 commit ae75f04
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions app/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,48 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Autoload\AutoloaderRegistry;
use Magento\Framework\Autoload\ClassLoaderWrapper;

/**
* Shortcut constant for the root directory
*/
define('BP', dirname(__DIR__));
\define('BP', \dirname(__DIR__));

define('VENDOR_PATH', BP . '/app/etc/vendor_path.php');
\define('VENDOR_PATH', BP . '/app/etc/vendor_path.php');

if (!file_exists(VENDOR_PATH)) {
if (!\is_readable(VENDOR_PATH)) {
throw new \Exception(
'We can\'t read some files that are required to run the Magento application. '
. 'This usually means file permissions are set incorrectly.'
);
}

$vendorDir = require VENDOR_PATH;
$vendorAutoload = BP . "/{$vendorDir}/autoload.php";
$vendorAutoload = (
static function (): ?string {
$vendorDir = require VENDOR_PATH;

$vendorAutoload = BP . "/{$vendorDir}/autoload.php";
if (\is_readable($vendorAutoload)) {
return $vendorAutoload;
}

$vendorAutoload = "{$vendorDir}/autoload.php";
if (\is_readable($vendorAutoload)) {
return $vendorAutoload;
}

return null;
}
)();

/* 'composer install' validation */
if (file_exists($vendorAutoload)) {
$composerAutoloader = include $vendorAutoload;
} else if (file_exists("{$vendorDir}/autoload.php")) {
$vendorAutoload = "{$vendorDir}/autoload.php";
$composerAutoloader = include $vendorAutoload;
} else {
if ($vendorAutoload === null) {
throw new \Exception(
'Vendor autoload is not found. Please run \'composer install\' under application root directory.'
);
}

$composerAutoloader = include $vendorAutoload;
AutoloaderRegistry::registerAutoloader(new ClassLoaderWrapper($composerAutoloader));

0 comments on commit ae75f04

Please sign in to comment.