Skip to content

Commit

Permalink
Improve configuration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
RoSk0 committed Nov 6, 2023
1 parent 900fddc commit c975009
Showing 1 changed file with 8 additions and 54 deletions.
62 changes: 8 additions & 54 deletions src/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,9 @@
class ConfigHelper
{
/**
* String with the location of this configuration.
* Used for error reporting.
* @var \SimpleSAML\Configuration
*/
private string $location;


/**
* The filesystem path to the Drupal directory
*/
private string $drupalRoot;


/**
* Whether debug output is enabled.
*
* @var bool
*/
private bool $debug;


/**
* The attributes we should fetch. Can be NULL in which case we will fetch all attributes.
*/
private ?array $attributes;


/**
* The Drupal logout URL
*/
private string $drupalLogoutUrl;


/**
* The Drupal login URL
*/
private string $drupalLoginUrl;

private Configuration $config;

/**
* Constructor for this configuration parser.
Expand All @@ -56,19 +22,7 @@ class ConfigHelper
*/
public function __construct(array $config, string $location)
{
assert(is_array($config));
assert(is_string($location));

$this->location = $location;

/* Get authsource configuration. */
$config = Configuration::loadFromArray($config, $location);

$this->drupalRoot = $config->getString('drupalroot');
$this->debug = $config->getOptionalBoolean('debug', false);
$this->attributes = $config->getOptionalArray('attributes', null);
$this->drupalLogoutUrl = $config->getString('drupal_logout_url');
$this->drupalLoginUrl = $config->getString('drupal_login_url');
$this->config = Configuration::loadFromArray($config, $location);
}

/**
Expand All @@ -78,7 +32,7 @@ public function __construct(array $config, string $location)
*/
public function getDebug(): bool
{
return $this->debug;
return $this->config->getOptionalBoolean('debug', false);
}

/**
Expand All @@ -88,7 +42,7 @@ public function getDebug(): bool
*/
public function getDrupalRoot(): string
{
return $this->drupalRoot;
return $this->config->getString('drupalroot');
}

/**
Expand All @@ -98,7 +52,7 @@ public function getDrupalRoot(): string
*/
public function getAttributes(): ?array
{
return $this->attributes;
return $this->config->getOptionalArray('attributes', null);
}


Expand All @@ -109,7 +63,7 @@ public function getAttributes(): ?array
*/
public function getDrupalLogoutUrl(): string
{
return $this->drupalLogoutUrl;
return $this->config->getString('drupal_logout_url');
}

/**
Expand All @@ -119,6 +73,6 @@ public function getDrupalLogoutUrl(): string
*/
public function getDrupalLoginUrl(): string
{
return $this->drupalLoginUrl;
return $this->config->getString('drupal_login_url');
}
}

0 comments on commit c975009

Please sign in to comment.