Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/run-random-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
################################################################################

set -u
export LC_NUMERIC=C
trap 'kill "${bg_pids[@]:-}" 2>/dev/null; wait 2>/dev/null' EXIT INT TERM

################################################################################
Expand Down
14 changes: 9 additions & 5 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class Autoloader
*/
protected $helpers = ['url'];

public function __construct(private readonly string $composerPath = COMPOSER_PATH)
{
}

/**
* Reads in the configuration array (described above) and stores
* the valid parts that we'll need.
Expand Down Expand Up @@ -127,7 +131,7 @@ public function initialize(Autoload $config, Modules $modules)
$this->helpers = [...$this->helpers, ...$config->helpers];
}

if (is_file(COMPOSER_PATH)) {
if (is_file($this->composerPath)) {
$this->loadComposerAutoloader($modules);
}

Expand All @@ -139,11 +143,11 @@ private function loadComposerAutoloader(Modules $modules): void
// The path to the vendor directory.
// We do not want to enforce this, so set the constant if Composer was used.
if (! defined('VENDORPATH')) {
define('VENDORPATH', dirname(COMPOSER_PATH) . DIRECTORY_SEPARATOR);
define('VENDORPATH', dirname($this->composerPath) . DIRECTORY_SEPARATOR);
}

/** @var ClassLoader $composer */
$composer = include COMPOSER_PATH;
$composer = include $this->composerPath;

// Should we load through Composer's namespaces, also?
if ($modules->discoverInComposer) {
Expand Down Expand Up @@ -451,14 +455,14 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa
*/
protected function discoverComposerNamespaces()
{
if (! is_file(COMPOSER_PATH)) {
if (! is_file($this->composerPath)) {
return;
}

/**
* @var ClassLoader $composer
*/
$composer = include COMPOSER_PATH;
$composer = include $this->composerPath;
$paths = $composer->getPrefixesPsr4();
$classes = $composer->getClassMap();

Expand Down
7 changes: 1 addition & 6 deletions tests/system/Autoloader/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,12 @@ public function testComposerPackagesOnlyAndExclude(): void

public function testFindsComposerRoutesWithComposerPathNotFound(): void
{
$composerPath = COMPOSER_PATH;

$config = new Autoload();
$modules = new Modules();
$modules->discoverInComposer = true;

$loader = new Autoloader();

rename(COMPOSER_PATH, COMPOSER_PATH . '.backup');
$loader = new Autoloader('/nonexistent/path/autoload.php');
$loader->initialize($config, $modules);
rename(COMPOSER_PATH . '.backup', $composerPath);

$namespaces = $loader->getNamespace();
$this->assertArrayNotHasKey('Laminas\\Escaper', $namespaces);
Expand Down
Loading