From 253bd0d601d13a67b913540586bb373ceed7784a Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tim.dijen@minbzk.nl> Date: Tue, 3 Jan 2023 11:29:35 +0100 Subject: [PATCH] Fix more concatenated calls to dirname --- bin/get-translatable-strings | 2 +- bin/importPdoMetadata.php | 2 +- bin/initMDSPdo.php | 2 +- bin/memcacheSync.php | 2 +- bin/pwgen.php | 2 +- docs/simplesamlphp-install.md | 6 +++--- modules/core/src/Controller/ErrorReport.php | 2 +- modules/cron/bin/cron.php | 2 +- src/SimpleSAML/Configuration.php | 2 +- src/SimpleSAML/Error/ConfigurationError.php | 2 +- src/SimpleSAML/Module.php | 4 ++-- src/SimpleSAML/Utils/Config.php | 2 +- tests/routers/configLoader.php | 2 +- tests/src/SimpleSAML/ConfigurationTest.php | 2 +- tests/src/SimpleSAML/ModuleTest.php | 2 +- tests/src/SimpleSAML/Utils/ConfigTest.php | 2 +- tests/src/SimpleSAML/XHTML/TemplateTranslationTest.php | 2 +- www/_include.php | 2 +- 18 files changed, 21 insertions(+), 21 deletions(-) diff --git a/bin/get-translatable-strings b/bin/get-translatable-strings index bc4a4f2e9..adbb53c33 100755 --- a/bin/get-translatable-strings +++ b/bin/get-translatable-strings @@ -19,7 +19,7 @@ use SimpleSAML\Utils; use Symfony\Component\Filesystem\Filesystem; // This is the base directory of the SimpleSAMLphp installation -$baseDir = dirname(dirname(__FILE__)); +$baseDir = dirname(__FILE__, 2); // Add library autoloader require_once($baseDir . '/src/_autoload.php'); diff --git a/bin/importPdoMetadata.php b/bin/importPdoMetadata.php index 271152a73..01c87b898 100755 --- a/bin/importPdoMetadata.php +++ b/bin/importPdoMetadata.php @@ -1,7 +1,7 @@ #!/usr/bin/env php <?php -$baseDir = dirname(dirname(__FILE__)); +$baseDir = dirname(__FILE__, 2); require_once $baseDir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . '_autoload.php'; require_once \SimpleSAML\Utils\Config::getConfigDir() . DIRECTORY_SEPARATOR . 'config.php'; diff --git a/bin/initMDSPdo.php b/bin/initMDSPdo.php index 79af70f12..d8387b437 100755 --- a/bin/initMDSPdo.php +++ b/bin/initMDSPdo.php @@ -2,7 +2,7 @@ <?php // This is the base directory of the SimpleSAMLphp installation -$baseDir = dirname(dirname(__FILE__)); +$baseDir = dirname(__FILE__, 2); // Add library autoloader and configuration require_once $baseDir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . '_autoload.php'; diff --git a/bin/memcacheSync.php b/bin/memcacheSync.php index 85bdbacfc..bbdbcf2f6 100755 --- a/bin/memcacheSync.php +++ b/bin/memcacheSync.php @@ -18,7 +18,7 @@ if (!class_exists('Memcache') && !class_exists('Memcached')) { } // This is the base directory of the SimpleSAMLphp installation -$baseDir = dirname(dirname(__FILE__)); +$baseDir = dirname(__FILE__, 2); // Add library autoloader require_once($baseDir . '/src/_autoload.php'); diff --git a/bin/pwgen.php b/bin/pwgen.php index 5980566bf..37f6c3482 100755 --- a/bin/pwgen.php +++ b/bin/pwgen.php @@ -7,7 +7,7 @@ */ // This is the base directory of the SimpleSAMLphp installation -$baseDir = dirname(dirname(__FILE__)); +$baseDir = dirname(__FILE__, 2); // Add library autoloader require_once($baseDir . '/src/_autoload.php'); diff --git a/docs/simplesamlphp-install.md b/docs/simplesamlphp-install.md index dcb6106b5..9523b5aac 100644 --- a/docs/simplesamlphp-install.md +++ b/docs/simplesamlphp-install.md @@ -434,13 +434,13 @@ Now, we need to make a few configuration changes. First, let's edit `~/public_ht Change the two lines from: ```php -require_once(dirname(dirname(__FILE__)) . '/lib/_autoload.php'); +require_once(dirname(_FILE__, 2) . '/lib/_autoload.php'); ``` to something like: -```bash -require_once(dirname(dirname(dirname(__FILE__))) . '/lib/_autoload.php'); +```php +require_once(dirname(__FILE__, 3) . '/lib/_autoload.php'); ``` **Warning**: note that this will make upgrading SimpleSAMLphp much more difficult, since you will need to move the diff --git a/modules/core/src/Controller/ErrorReport.php b/modules/core/src/Controller/ErrorReport.php index b5cee781e..dabe55df8 100644 --- a/modules/core/src/Controller/ErrorReport.php +++ b/modules/core/src/Controller/ErrorReport.php @@ -97,7 +97,7 @@ class ErrorReport $data['reportId'] = $reportId; $data['version'] = $this->config->getVersion(); $data['hostname'] = php_uname('n'); - $data['directory'] = dirname(dirname(__FILE__)); + $data['directory'] = dirname(__FILE__, 2); if ($this->config->getOptionalBoolean('errorreporting', true)) { $mail = new Utils\EMail('SimpleSAMLphp error report from ' . $email); diff --git a/modules/cron/bin/cron.php b/modules/cron/bin/cron.php index b68bf8523..4049106d3 100755 --- a/modules/cron/bin/cron.php +++ b/modules/cron/bin/cron.php @@ -8,7 +8,7 @@ */ // This is the base directory of the SimpleSAMLphp installation -$baseDir = dirname(dirname(dirname(dirname(__FILE__)))); +$baseDir = dirname(__FILE__, 4); // Add library autoloader. require_once($baseDir . '/src/_autoload.php'); diff --git a/src/SimpleSAML/Configuration.php b/src/SimpleSAML/Configuration.php index 83ce66e19..050a96b25 100644 --- a/src/SimpleSAML/Configuration.php +++ b/src/SimpleSAML/Configuration.php @@ -229,7 +229,7 @@ class Configuration implements Utils\ClearableState if ($configSet !== 'simplesaml') { throw new Exception('Configuration set \'' . $configSet . '\' not initialized.'); } else { - self::$configDirs['simplesaml'] = dirname(dirname(dirname(__FILE__))) . '/config'; + self::$configDirs['simplesaml'] = dirname(__FILE__, 3) . '/config'; } } diff --git a/src/SimpleSAML/Error/ConfigurationError.php b/src/SimpleSAML/Error/ConfigurationError.php index bc0d9c261..531571c0b 100644 --- a/src/SimpleSAML/Error/ConfigurationError.php +++ b/src/SimpleSAML/Error/ConfigurationError.php @@ -41,7 +41,7 @@ class ConfigurationError extends Error $params = ['CONFIG']; if ($file !== null) { $params['%FILE%'] = $file; - $basepath = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; + $basepath = dirname(__FILE__, 4) . '/'; $file_str = '(' . str_replace($basepath, '', $file) . ') '; } if ($reason !== null) { diff --git a/src/SimpleSAML/Module.php b/src/SimpleSAML/Module.php index 56130313d..d3b5dc195 100644 --- a/src/SimpleSAML/Module.php +++ b/src/SimpleSAML/Module.php @@ -124,7 +124,7 @@ class Module */ public static function getModuleDir(string $module): string { - $baseDir = dirname(dirname(dirname(__FILE__))) . '/modules'; + $baseDir = dirname(__FILE__, 3) . '/modules'; $moduleDir = $baseDir . '/' . $module; return $moduleDir; @@ -505,7 +505,7 @@ class Module } $hooks = []; - $hook_dir = Path::canonicalize(dirname(dirname(dirname(__FILE__))) . '/modules/' . $module . '/hooks'); + $hook_dir = Path::canonicalize(dirname(__FILE__, 3) . '/modules/' . $module . '/hooks'); if ((new Filesystem())->exists($hook_dir)) { $finder = new Finder(); $finder->files()->in($hook_dir)->depth(0); diff --git a/src/SimpleSAML/Utils/Config.php b/src/SimpleSAML/Utils/Config.php index 567ad67de..e96534095 100644 --- a/src/SimpleSAML/Utils/Config.php +++ b/src/SimpleSAML/Utils/Config.php @@ -65,7 +65,7 @@ class Config */ public function getConfigDir(): string { - $configDir = dirname(dirname(dirname(__DIR__))) . '/config'; + $configDir = dirname(__DIR__, 3) . '/config'; $configDirEnv = getenv('SIMPLESAMLPHP_CONFIG_DIR'); if ($configDirEnv === false) { diff --git a/tests/routers/configLoader.php b/tests/routers/configLoader.php index 5fa2b8888..d9af33565 100644 --- a/tests/routers/configLoader.php +++ b/tests/routers/configLoader.php @@ -35,7 +35,7 @@ use SimpleSAML\Configuration; include_once(sys_get_temp_dir() . '/' . getmypid() . '.lock'); // load SimpleSAMLphp's autoloader -require_once(dirname(dirname(dirname(__FILE__))) . '/vendor/autoload.php'); +require_once(dirname(__FILE__, 3) . '/vendor/autoload.php'); // initialize configuration if (isset($config)) { diff --git a/tests/src/SimpleSAML/ConfigurationTest.php b/tests/src/SimpleSAML/ConfigurationTest.php index 719003bab..013e4721e 100644 --- a/tests/src/SimpleSAML/ConfigurationTest.php +++ b/tests/src/SimpleSAML/ConfigurationTest.php @@ -234,7 +234,7 @@ class ConfigurationTest extends ClearStateTestCase public function testGetBaseDir(): void { $c = Configuration::loadFromArray([]); - $this->assertEquals($c->getBaseDir(), dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR); + $this->assertEquals($c->getBaseDir(), dirname(__FILE__, 4) . DIRECTORY_SEPARATOR); $c = Configuration::loadFromArray([ 'basedir' => DIRECTORY_SEPARATOR . 'basedir', diff --git a/tests/src/SimpleSAML/ModuleTest.php b/tests/src/SimpleSAML/ModuleTest.php index c5bb51e3c..19138c838 100644 --- a/tests/src/SimpleSAML/ModuleTest.php +++ b/tests/src/SimpleSAML/ModuleTest.php @@ -32,7 +32,7 @@ class ModuleTest extends TestCase { // test for the most basic functionality $this->assertEquals( - Path::canonicalize(dirname(dirname(dirname(dirname(__FILE__)))) . '/modules/module'), + Path::canonicalize(dirname(__FILE__, 4) . '/modules/module'), Path::canonicalize(Module::getModuleDir('module')), ); } diff --git a/tests/src/SimpleSAML/Utils/ConfigTest.php b/tests/src/SimpleSAML/Utils/ConfigTest.php index 2e75b09d6..34cefef55 100644 --- a/tests/src/SimpleSAML/Utils/ConfigTest.php +++ b/tests/src/SimpleSAML/Utils/ConfigTest.php @@ -40,7 +40,7 @@ class ConfigTest extends TestCase putenv('SIMPLESAMLPHP_CONFIG_DIR'); $configDir = $this->configUtils->getConfigDir(); - $this->assertEquals($configDir, dirname(dirname(dirname(dirname(__DIR__)))) . '/config'); + $this->assertEquals($configDir, dirname(__DIR__, 4) . '/config'); } diff --git a/tests/src/SimpleSAML/XHTML/TemplateTranslationTest.php b/tests/src/SimpleSAML/XHTML/TemplateTranslationTest.php index 07089206f..9637a3445 100644 --- a/tests/src/SimpleSAML/XHTML/TemplateTranslationTest.php +++ b/tests/src/SimpleSAML/XHTML/TemplateTranslationTest.php @@ -126,7 +126,7 @@ class TemplateTranslationTest extends TestCase public function testValidateTwigFiles(): void { - $root = dirname(dirname((dirname(dirname(__DIR__))))); + $root = dirname(__DIR__, 4); // Setup basic twig environment $loader = new FilesystemLoader(['templates', 'modules'], $root); diff --git a/www/_include.php b/www/_include.php index cf3f99129..25eeb52a8 100644 --- a/www/_include.php +++ b/www/_include.php @@ -3,7 +3,7 @@ declare(strict_types=1); // initialize the autoloader -require_once(dirname(dirname(__FILE__)) . '/src/_autoload.php'); +require_once(dirname(__FILE__, 2) . '/src/_autoload.php'); use SAML2\Compat\ContainerSingleton; use SimpleSAML\Compat\SspContainer; -- GitLab