Skip to content

Commit

Permalink
Update MultiVersion.php
Browse files Browse the repository at this point in the history
Removed throws and use SimpleSamlPHP's logger class
  • Loading branch information
YOUR1 authored Apr 21, 2022
1 parent e7d33b9 commit df6f3d5
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/MultiVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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."
);
}
Expand All @@ -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."
);
}
Expand All @@ -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."
);
}
Expand All @@ -105,7 +101,6 @@ private function validateYamlConfigState() : void {
* @global $config
*
* @return array
* @throws \Exception
*/
public function getMainConfig( string $environment = null ) : array {
// Validate config state
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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."
);
}
Expand All @@ -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."
);
}
Expand All @@ -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."
);
}
Expand Down Expand Up @@ -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 ) ) {
Expand Down

0 comments on commit df6f3d5

Please sign in to comment.