Skip to content

Instantly share code, notes, and snippets.

@aklump
Created April 30, 2025 21:41
Show Gist options
  • Save aklump/a1bd4a5b6009b1d080cf2e66f993c46f to your computer and use it in GitHub Desktop.
Save aklump/a1bd4a5b6009b1d080cf2e66f993c46f to your computer and use it in GitHub Desktop.
snippet to load composer autoload
// https://getcomposer.org/doc/articles/vendor-binaries.md#finding-the-composer-autoloader-from-a-binary
if (isset($GLOBALS['_composer_autoload_path'])) {
// As of Composer 2.2...
$_composer_autoload_path = $GLOBALS['_composer_autoload_path'];
}
else {
// < Composer 2.2
foreach ([
__DIR__ . '/../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php',
] as $_composer_autoload_path) {
if (file_exists($_composer_autoload_path)) {
break;
}
}
}
$class_loader = require_once $_composer_autoload_path;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment