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
16 changes: 2 additions & 14 deletions .github/workflows/test-random-execution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,6 @@ jobs:
extensions: gd, curl, iconv, json, mbstring, openssl, sodium
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }}
key: PHP_${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}
restore-keys: |
PHP_${{ matrix.php-version }}-

- name: Install project dependencies
run: |
composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -213,8 +201,8 @@ jobs:
args+=("--max-jobs" "${{ inputs.max-jobs }}")
fi

# Add --repeat flag (always, default is 10)
args+=("--repeat" "${{ inputs.repeat || '10' }}")
# Add --repeat flag (always, default is 50)
args+=("--repeat" "${{ inputs.repeat || '50' }}")

# Add --timeout flag (always, default is 300)
args+=("--timeout" "${{ inputs.timeout || '300' }}")
Expand Down
55 changes: 33 additions & 22 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Kint\Kint;
use Kint\Renderer\CliRenderer;
use Kint\Renderer\RichRenderer;
use Throwable;

/**
* An autoloader that uses both PSR4 autoloading, and traditional classmaps.
Expand Down Expand Up @@ -146,16 +147,24 @@ private function loadComposerAutoloader(Modules $modules): void
define('VENDORPATH', dirname($this->composerPath) . DIRECTORY_SEPARATOR);
}

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

// Should we load through Composer's namespaces, also?
if ($modules->discoverInComposer) {
$composerPackages = $modules->composerPackages;
$this->loadComposerNamespaces($composer, $composerPackages ?? []);
}
// Should we load through Composer's namespaces, also?
if ($modules->discoverInComposer) {
$composerPackages = $modules->composerPackages;
$this->loadComposerNamespaces($composer, $composerPackages ?? []);
}

unset($composer);
unset($composer);
} catch (ConfigException $e) {
// Re-throw configuration exceptions
throw $e;
} catch (Throwable) {
// If Composer fails to load for other reasons, continue
// The SPL autoloader will still work for CodeIgniter's own classes
}
}

/**
Expand All @@ -170,8 +179,8 @@ private function loadComposerAutoloader(Modules $modules): void
*/
public function register()
{
spl_autoload_register($this->loadClassmap(...), true);
spl_autoload_register($this->loadClass(...), true);
spl_autoload_register($this->loadClassmap(...), prepend: true);
spl_autoload_register($this->loadClass(...), prepend: true);

foreach ($this->files as $file) {
$this->includeFile($file);
Expand All @@ -196,22 +205,24 @@ public function unregister(): void
*/
public function addNamespace($namespace, ?string $path = null)
{
if (is_array($namespace)) {
foreach ($namespace as $prefix => $namespacedPath) {
$prefix = trim($prefix, '\\');
if (is_string($namespace)) {
if ($path === null) {
return $this;
}

if (is_array($namespacedPath)) {
foreach ($namespacedPath as $dir) {
$this->prefixes[$prefix][] = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR;
}
$namespace = [$namespace => $path];
}

continue;
}
foreach ($namespace as $prefix => $paths) {
$prefix = trim($prefix, '\\');

$this->prefixes[$prefix][] = rtrim($namespacedPath, '\\/') . DIRECTORY_SEPARATOR;
if (is_string($paths)) {
$paths = [$paths];
}

foreach ($paths as $path) {
$this->prefixes[$prefix][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
}
} else {
$this->prefixes[trim($namespace, '\\')][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
}

return $this;
Expand Down
Loading