bugfix/30517-check-mode-for-demo-not-domain #1
1 changed files with 33 additions and 24 deletions
|
|
@ -29,7 +29,7 @@ namespace rabe\Util;
|
|||
class Settings implements \Iterator, \Countable
|
||||
{
|
||||
private const SITE = 0x01;
|
||||
|
||||
|
||||
private array $settings = [];
|
||||
|
||||
private string $appPath = './';
|
||||
|
|
@ -68,7 +68,7 @@ class Settings implements \Iterator, \Countable
|
|||
public function appPath( ?string $path=null )
|
||||
{
|
||||
if (! isset($path)) return $this->appPath;
|
||||
|
||||
|
||||
if ($this->pkgPath === $this->appPath) $this->pkgPath = $path;
|
||||
$this->appPath = $path;
|
||||
return $this;
|
||||
|
|
@ -105,7 +105,7 @@ class Settings implements \Iterator, \Countable
|
|||
$this->modes += $modes;
|
||||
return $this;
|
||||
}// }}}
|
||||
|
||||
|
||||
// site() {{{
|
||||
/** {{{
|
||||
*///}}}
|
||||
|
|
@ -114,7 +114,7 @@ class Settings implements \Iterator, \Countable
|
|||
$this->site = $site;
|
||||
return $this;
|
||||
}// }}}
|
||||
|
||||
|
||||
// load() method {{{
|
||||
/** {{{
|
||||
* Load the configuration from the files and merge them
|
||||
|
|
@ -129,12 +129,12 @@ class Settings implements \Iterator, \Countable
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
$modes = $this->modes;
|
||||
|
||||
|
||||
// load Prefix.default.conf.php
|
||||
$defaultConf = $this->buildFileName( array_shift($modes) );
|
||||
|
||||
|
||||
if ( file_exists($defaultConf) )
|
||||
{
|
||||
$this->settings = require( $defaultConf );
|
||||
|
|
@ -145,17 +145,17 @@ class Settings implements \Iterator, \Countable
|
|||
throw new \Exception( "No settingsfile: $defaultConf" );
|
||||
// throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
|
||||
// add modes from the drfault config file (no modes from other files are added)
|
||||
if (isset($this->settings['modes'])) {
|
||||
$this->addModes($this->settings['modes']);
|
||||
}
|
||||
|
||||
|
||||
// load local config without merging - we need it here for the mode
|
||||
$conf = $this->buildFileName();
|
||||
$localConf = false;
|
||||
if (file_exists($conf)) $localConf = require($conf);
|
||||
|
||||
|
||||
// if a mode was set in the constructor do not overwrite it
|
||||
if (! isset($this->mode)) {
|
||||
// if a localConf Mode is set use it, or take the default conf mode
|
||||
|
|
@ -163,7 +163,7 @@ class Settings implements \Iterator, \Countable
|
|||
} else {
|
||||
$this->settings['mode'] = $this->mode;
|
||||
}
|
||||
|
||||
|
||||
if ( isset($this->site) )
|
||||
{
|
||||
$siteConf = $this->buildFileName(self::SITE);
|
||||
|
|
@ -172,12 +172,12 @@ class Settings implements \Iterator, \Countable
|
|||
$localConf = array_replace_recursive($this->settings, require($siteConf));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// load and merge Prefix.mode.conf.php
|
||||
if ( isset( $this->modes[ $this->mode ] ) )
|
||||
{
|
||||
$modeConf = $this->buildFileName( $this->modes[ $this->mode ] );
|
||||
|
||||
|
||||
if ( file_exists($modeConf) )
|
||||
{
|
||||
$this->settings = array_replace_recursive( $this->settings, require($modeConf) );
|
||||
|
|
@ -192,14 +192,14 @@ class Settings implements \Iterator, \Countable
|
|||
// log invalid mode
|
||||
throw new \Exception( "The mode '{$this->mode}' is not valid" );
|
||||
}
|
||||
|
||||
|
||||
// merge Prefix.conf.php (localConf)
|
||||
if ($localConf !== false)
|
||||
{
|
||||
$this->settings = array_replace_recursive( $this->settings, $localConf );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// echo "<pre>"; print_r( $this->settings ); echo "</pre>";
|
||||
return $this;
|
||||
}// }}}
|
||||
|
|
@ -209,9 +209,9 @@ class Settings implements \Iterator, \Countable
|
|||
*///}}}
|
||||
public function mergeFile( )
|
||||
{
|
||||
|
||||
|
||||
}// }}}
|
||||
|
||||
|
||||
// create() {{{
|
||||
/** {{{
|
||||
* Creates a copy of the Settingsobject without the configuration directives
|
||||
|
|
@ -233,15 +233,15 @@ class Settings implements \Iterator, \Countable
|
|||
{
|
||||
$mode = '';
|
||||
$path = $this->appPath.$this->confDir;
|
||||
|
||||
|
||||
if ($type === self::SITE) $path .= $this->site.'/';
|
||||
|
||||
|
||||
if (is_string( $type ) &! empty( $type ))
|
||||
{
|
||||
$mode = "$type.";
|
||||
$path = $this->pkgPath.$this->confDir;
|
||||
}
|
||||
|
||||
|
||||
return $path.$this->filePrefix.$mode.$this->filePostfix;
|
||||
}
|
||||
// }}}
|
||||
|
|
@ -324,7 +324,7 @@ class Settings implements \Iterator, \Countable
|
|||
count($this->settings);
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
// Magic getter/setter methods {{{
|
||||
public function __set( $name, $value )
|
||||
{
|
||||
|
|
@ -352,10 +352,19 @@ class Settings implements \Iterator, \Countable
|
|||
{
|
||||
unset( $this->settings[$name] );
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
public function __call(string $name, array $arguments)
|
||||
{
|
||||
$type = substr($name, 0, 3);
|
||||
if ($type === 'get') {
|
||||
$propertyName = lcfirst(substr($name , 3));
|
||||
return (is_array( $this->settings[$propertyName] ))
|
||||
? $this->create( $this->settings[$propertyName] )
|
||||
: $this->settings[$propertyName]; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* jEdit buffer local properties {{{
|
||||
* :folding=explicit:collapseFolds=1:
|
||||
}}}*/
|
||||
}}}*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue