openrat-webdav

git clone http://git.code.weiherhei.de/openrat-webdav.git
Log | Files | Refs

commit 2c39b18581f9a24ed70bb231580c79bebe0b64c5
parent 8abe9b38635d1cd4508c007aa7b1f2b4aa200121
Author: Jan Dankert <develop@jandankert.de>
Date:   Wed,  6 Nov 2019 23:14:55 +0100

Refactoring: Externalize config reader

Diffstat:
config.php | 39+++++++++++++++++++++++++++++++++++++++
dav.php | 37+------------------------------------
2 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/config.php b/config.php @@ -0,0 +1,39 @@ +<?php + +// Default-Configuration. +$config = array('dav.enable' => false, + 'dav.create' => true, + 'dav.readonly' => false, + 'dav.expose_openrat' => true, + 'dav.compliant_to_redmond' => true, + 'dav.redirect_collections_to_trailing_slash' => true, + 'dav.realm' =>'OpenRat CMS WebDAV Login', + 'dav.anonymous' => false, + 'cms.host' => 'localhost', + 'cms.port' => 80, + 'cms.username' => null, + 'cms.password' => null, + 'cms.database' => 'db1', + 'cms.path' => '/', + 'cms.max_file_size' => 1000, + 'log.level' => 'info', + 'log.file' => null +); + +// Configuration-Loader +foreach( array( + 'dav-'.$_SERVER['HTTP_HOST'].'.ini', + @$_ENV['dav.config.file'], + 'dav.ini', + '/etc/openrat-webdav.ini' + ) as $iniFile ) + if ( is_file($iniFile)) + $config = array_merge($config,parse_ini_file( $iniFile) ); + + +// Config values are overwritable by Environment variables. +array_walk($config, function(&$value,$key) { + $envkey = strtoupper(str_replace('.','_',$key)); + if ( @$_ENV[$envkey] ) + $value = $_ENV[$envkey]; +} ); diff --git a/dav.php b/dav.php @@ -31,43 +31,8 @@ if (!defined('E_STRICT')) define('TIME_20000101',946681200); // default time for objects without time information. -// Default-Configuration. -$config = array('dav.enable' => false, - 'dav.create' => true, - 'dav.readonly' => false, - 'dav.expose_openrat' => true, - 'dav.compliant_to_redmond' => true, - 'dav.redirect_collections_to_trailing_slash' => true, - 'dav.realm' =>'OpenRat CMS WebDAV Login', - 'dav.anonymous' => false, - 'cms.host' => 'localhost', - 'cms.port' => 80, - 'cms.username' => null, - 'cms.password' => null, - 'cms.database' => 'db1', - 'cms.path' => '/', - 'cms.max_file_size' => 1000, - 'log.level' => 'info', - 'log.file' => null - ); - -// Configuration-Loader -foreach( array( - 'dav-'.$_SERVER['HTTP_HOST'].'.ini', - @$_ENV['dav.config.file'], - 'dav.ini', - '/etc/openrat-webdav.ini' - ) as $iniFile ) - if ( is_file($iniFile)) - $config = array_merge($config,parse_ini_file( $iniFile) ); - - -// Config values are overwritable by Environment variables. -array_walk($config, function(&$value,$key) { - if ( @$_ENV[$key] ) - $value = $_ENV[$key]; -} ); +require('./config.php'); require('./cms/Client.class.php'); require('./cms/CMS.class.php');