Skip to content
Snippets Groups Projects
Unverified Commit bb1abe67 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Cleanup: autoloader files (#1635)

parent 05e696c5
No related branches found
No related tags found
No related merge requests found
...@@ -21,9 +21,14 @@ ...@@ -21,9 +21,14 @@
], ],
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"SimpleSAML\\": "lib/SimpleSAML" "SimpleSAML\\": "lib/SimpleSAML",
}, "SimpleSAML\\Module\\admin\\": "modules/admin/lib",
"files": ["lib/_autoload_modules.php"] "SimpleSAML\\Module\\core\\": "modules/core/lib",
"SimpleSAML\\Module\\cron\\": "modules/cron/lib",
"SimpleSAML\\Module\\exampleauth\\": "modules/exampleauth/lib",
"SimpleSAML\\Module\\multiauth\\": "modules/multiauth/lib",
"SimpleSAML\\Module\\saml\\": "modules/saml/lib"
}
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
...@@ -34,8 +39,7 @@ ...@@ -34,8 +39,7 @@
"SimpleSAML\\Test\\Module\\exampleauth\\": ["tests/lib/SimpleSAML/modules/exampleauth/lib"], "SimpleSAML\\Test\\Module\\exampleauth\\": ["tests/lib/SimpleSAML/modules/exampleauth/lib"],
"SimpleSAML\\Test\\Module\\multiauth\\": ["tests/lib/SimpleSAML/modules/multiauth/lib"], "SimpleSAML\\Test\\Module\\multiauth\\": ["tests/lib/SimpleSAML/modules/multiauth/lib"],
"SimpleSAML\\Test\\Module\\saml\\": ["tests/lib/SimpleSAML/modules/saml/lib"] "SimpleSAML\\Test\\Module\\saml\\": ["tests/lib/SimpleSAML/modules/saml/lib"]
}, }
"files": ["tests/_autoload_modules.php"]
}, },
"require": { "require": {
"php": ">=7.4 || ^8.0", "php": ">=7.4 || ^8.0",
......
<?php
/**
* This file is a backwards compatible autoloader for SimpleSAMLphp.
* Loads the Composer autoloader.
*
* @package SimpleSAMLphp
*/
declare(strict_types=1);
// 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');
}
}
<?php
declare(strict_types=1);
/**
* This file registers an autoloader for SimpleSAMLphp modules.
*
* @package SimpleSAMLphp
*/
/**
* Autoload function for SimpleSAMLphp modules following PSR-4.
*
* @param string $className Name of the class.
*/
function sspmodAutoloadPSR4(string $className): void
{
$elements = explode('\\', $className);
if ($elements[0] === '') {
// class name starting with /, ignore
array_shift($elements);
}
if (count($elements) < 4) {
return; // it can't be a module
}
if (array_shift($elements) !== 'SimpleSAML') {
return; // the first element is not "SimpleSAML"
}
if (array_shift($elements) !== 'Module') {
return; // the second element is not "module"
}
// this is a SimpleSAMLphp module following PSR-4
$module = array_shift($elements);
if (!\SimpleSAML\Module::isModuleEnabled($module)) {
return; // module not enabled, avoid giving out any information at all
}
$file = \SimpleSAML\Module::getModuleDir($module) . '/lib/' . implode('/', $elements) . '.php';
if (file_exists($file)) {
require_once($file);
}
}
spl_autoload_register('sspmodAutoloadPSR4');
<?php
declare(strict_types=1);
/**
* This file registers an autoloader for test classes used by SimpleSAMLphp modules unit tests.
*/
/**
* Autoload function for SimpleSAMLphp modules test classes following PSR-4.
* Module test classes have namespaces like SimpleSAML\Test\Module\<moduleName>\Auth\Process
*
* @param string $className Name of the class.
*/
function sspmodTestClassAutoloadPSR4(string $className): void
{
$elements = explode('\\', $className);
if ($elements[0] === '') {
// class name starting with /, ignore
array_shift($elements);
}
if (count($elements) < 5) {
return; // it can't be a module test class
}
if (array_shift($elements) !== 'SimpleSAML') {
return; // the first element is not "SimpleSAML"
}
if (array_shift($elements) !== 'Test') {
return; // the second element is not "test"
}
if (array_shift($elements) !== 'Module') {
return; // the third element is not "module"
}
// this is a SimpleSAMLphp module test class following PSR-4
$module = array_shift($elements);
$moduleTestDir = __DIR__ . '/modules/' . $module;
$file = $moduleTestDir . '/lib/' . implode('/', $elements) . '.php';
if (file_exists($file)) {
require_once($file);
}
}
spl_autoload_register('sspmodTestClassAutoloadPSR4');
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace SimpleSAML\Test;
use SimpleSAML\Configuration; use SimpleSAML\Configuration;
/* /*
......
<?php <?php
// initialize the autoloader
require_once(dirname(dirname(__FILE__)) . '/lib/_autoload.php');
use SAML2\Compat\ContainerSingleton; use SAML2\Compat\ContainerSingleton;
use SimpleSAML\Compat\SspContainer; use SimpleSAML\Compat\SspContainer;
use SimpleSAML\Configuration; use SimpleSAML\Configuration;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment