Skip to content

Instantly share code, notes, and snippets.

@codebymikey
Last active February 15, 2023 13:10
Show Gist options
  • Save codebymikey/bef20026ebbda8c1205b0183ec8ce739 to your computer and use it in GitHub Desktop.
Save codebymikey/bef20026ebbda8c1205b0183ec8ce739 to your computer and use it in GitHub Desktop.
SimpleSAMLPHP custom install autoloader support.
diff --git a/lib/_autoload.php b/lib/_autoload.php
index e44c70f97..75945f742 100644
--- a/lib/_autoload.php
+++ b/lib/_autoload.php
@@ -8,14 +8,21 @@
* @package SimpleSAMLphp
*/
-// SSP is loaded as a separate project
-if (file_exists(dirname(dirname(__FILE__)) . '/vendor/autoload.php')) {
- require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';
-} else {
- // SSP is loaded as a library
- if (file_exists(dirname(dirname(__FILE__)) . '/../../autoload.php')) {
- require_once dirname(dirname(__FILE__)) . '/../../autoload.php';
- } else {
- throw new Exception('Unable to load Composer autoloader');
+$directory = dirname(__DIR__);
+$autoload_candidates = [
+ // SSP is loaded as a separate project
+ dirname(__DIR__) . '/vendor/autoload.php',
+ // SSP is loaded as a custom install path in the root.
+ dirname(__DIR__, 2) . '/vendor/autoload.php',
+ // SSP is loaded as a library.
+ dirname(__DIR__, 3) . "/autoload.php",
+];
+
+foreach ($autoload_candidates as $autoload_candidate) {
+ if (file_exists($autoload_candidate)) {
+ require_once $autoload_candidate;
+ return;
}
}
+
+throw new Exception('Unable to load Composer autoloader');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment