From df6f3d5d4ec3ec86e3e8c3ed5877835d90a1ebbb Mon Sep 17 00:00:00 2001 From: Youri vd Bogert Date: Thu, 21 Apr 2022 16:38:24 +0200 Subject: [PATCH] Update MultiVersion.php Removed throws and use SimpleSamlPHP's logger class --- src/MultiVersion.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/MultiVersion.php b/src/MultiVersion.php index 9f0f9b3..c93fd01 100644 --- a/src/MultiVersion.php +++ b/src/MultiVersion.php @@ -34,19 +34,17 @@ class MultiVersion { /** * @param string $defaultConfigFile * @param string $yamlConfigDirectory - * - * @throws \Exception */ public function __construct( string $defaultConfigFile, string $yamlConfigDirectory ) { if ( ! file_exists( $defaultConfigFile ) ) { - throw new \Exception( + \SimpleSAML\Logger::error( "Default configuration file ({$defaultConfigFile}) could not be found." ); } if ( ! is_dir( $yamlConfigDirectory ) ) { - throw new \Exception( + \SimpleSAML\Logger::error( "Given directory ({$yamlConfigDirectory}} does not exist." ); } @@ -55,13 +53,13 @@ public function __construct( string $defaultConfigFile, string $yamlConfigDirect $yamlAuthsourcesFile = $yamlConfigDirectory . DIRECTORY_SEPARATOR . "authsources.yaml"; if ( ! file_exists( $yamlConfigFile ) ) { - throw new \Exception( + \SimpleSAML\Logger::error( "Yaml configuration file ({$$yamlConfigFile}) could not be found." ); } if ( ! file_exists( $yamlAuthsourcesFile ) ) { - throw new \Exception( + \SimpleSAML\Logger::error( "Yaml authsources configuration file ({$yamlAuthsourcesFile}) could not be found." ); } @@ -87,12 +85,10 @@ public function __construct( string $defaultConfigFile, string $yamlConfigDirect * to configure. * * This checks both the main and auth sources config files. - * - * @throws \Exception */ private function validateYamlConfigState() : void { if ( empty( $this->yamlMainConfig ) || empty ( $this->yamlAuthsourcesConfig ) ) { - throw new \Exception( + \SimpleSAML\Logger::error( "Configuration missmatch. The YAML configuration container is empty." ); } @@ -105,7 +101,6 @@ private function validateYamlConfigState() : void { * @global $config * * @return array - * @throws \Exception */ public function getMainConfig( string $environment = null ) : array { // Validate config state @@ -144,7 +139,6 @@ public function getMainConfig( string $environment = null ) : array { * @param string|null $environment * * @return array|array[] - * @throws \Exception */ public function getMetaRefreshConfig( string $environment = null ) : array { // Validate config state @@ -200,7 +194,6 @@ public function getMetaRefreshConfig( string $environment = null ) : array { * @param string|null $environment * * @return array - * @throws \Exception */ public function getAuthSourcesConfig( string $environment = null ) : array { // Validate config state @@ -236,7 +229,6 @@ public function getAuthSourcesConfig( string $environment = null ) : array { * Returns the compiled module_cron.php configuration object. * * @return array - * @throws \Exception */ public function getCronConfig() : array { // Validate config state @@ -245,7 +237,7 @@ public function getCronConfig() : array { // We need an actual config object to make this thing work $cronConfig = $this->yamlMainConfig[ 'modules' ][ 'cron' ] ?? false; if ( ! $cronConfig ) { - throw new \Exception( + \SimpleSAML\Logger::error( "There was no cron configuration." ); } @@ -258,7 +250,7 @@ public function getCronConfig() : array { // The key and allowed_tags are mandatory for the cron module to work // so lets require them if ( ! $cronKey || ! $allowedTags ) { - throw new \Exception( + \SimpleSAML\Logger::error( "Cron configuration is missing key or allowed_tags." ); } @@ -275,12 +267,11 @@ public function getCronConfig() : array { * @param string $environment * * @return string - * @throws \Exception */ private function getBaseUrlPath( string $environment ) : string { if ( ! isset( $this->yamlMainConfig[ 'environments' ][ $environment ] ) ) { - throw new \Exception( + \SimpleSAML\Logger::error( "Environment: $environment is not configured." ); } @@ -328,7 +319,6 @@ private function flattenYamlConfigArray( array $array, $prefix = '' ) : array { * @param string $yamlConfigurationDirectory * * @return MultiVersion - * @throws \Exception */ public static function factory( string $defaultConfig, string $yamlConfigurationDirectory ) : MultiVersion { if ( !isset ( self::$instance ) ) {