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