Skip to content

Instantly share code, notes, and snippets.

@aklump
Last active November 8, 2025 17:07
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
$ds = DIRECTORY_SEPARATOR;
foreach ([
__DIR__ . $ds . '..' . $ds . '..' . $ds . 'autoload.php',
__DIR__ . $ds . '..' . $ds . 'vendor' . $ds . 'autoload.php',
__DIR__ . $ds . 'vendor' . $ds . '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