improved configuration loader, autoload is now compatible with windows

This commit is contained in:
Juan 2018-06-06 13:11:06 +02:00
parent e458b72748
commit b7a43145ca
6 changed files with 19 additions and 15 deletions

View File

@ -346,7 +346,7 @@ class Connection {
$i = 0; $i = 0;
$params = []; $params = [];
foreach($paramsMap as $key => $value) foreach ($paramsMap as $key => $value)
$params[$key] = $this->renderValue($value); $params[$key] = $this->renderValue($value);
$replaceFunc = function($matches) use(&$params, &$i) { $replaceFunc = function($matches) use(&$params, &$i) {

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
php-vn-lib (2.1.4) stable; urgency=low php-vn-lib (2.1.5) stable; urgency=low
* Initial Release. * Initial Release.

View File

@ -85,14 +85,18 @@ class App {
*/ */
function getConfigFile() { function getConfigFile() {
$configDir = _CONFIG_DIR .'/'. $this->name; $configDir = _CONFIG_DIR .'/'. $this->name;
$customFile = "$configDir/config.my.php";
if (file_exists('config.php')) $configFiles = [
return 'config.php'; "$configDir/config.my.php",
else if (file_exists($customFile)) "$configDir/config.php",
return $customFile; "config.my.php"
else ];
return "$configDir/config.php";
foreach ($configFiles as $configFile)
if (file_exists($configFile))
return $configFile;
return 'config.php';
} }
/** /**

View File

@ -33,7 +33,7 @@ namespace Vn\Lib {
setlocale(LC_ALL, $locale); setlocale(LC_ALL, $locale);
self::$localeSet = TRUE; self::$localeSet = TRUE;
foreach(self::$paths as $path => $kk) foreach (self::$paths as $path => $kk)
self::loadFile($path); self::loadFile($path);
} }
@ -93,7 +93,7 @@ namespace Vn\Lib {
* translation * translation
*/ */
static function addTranslations($strings) { static function addTranslations($strings) {
foreach($strings as $string => &$translation) foreach ($strings as $string => &$translation)
self::$strings[$string] = &$translation; self::$strings[$string] = &$translation;
} }
} }

View File

@ -47,7 +47,7 @@ abstract class Method {
if (!isset($map)) if (!isset($map))
return FALSE; return FALSE;
foreach($params as $param) foreach ($params as $param)
if (!isset($map[$param])) { if (!isset($map[$param])) {
return FALSE; return FALSE;
break; break;

View File

@ -6,7 +6,7 @@ $vnAutoloadReplace = function($matches) {
if (strlen($match) == 1) if (strlen($match) == 1)
return $match; return $match;
if ($match{0} == '\\') if ($match{0} == '\\')
return DIRECTORY_SEPARATOR. $match{1}; return '/'. $match{1};
return $match{0} .'-'. $match{1}; return $match{0} .'-'. $match{1};
}; };
@ -18,7 +18,7 @@ spl_autoload_register(function($className) {
$classPath .= '.php'; $classPath .= '.php';
if (isset($vnAutoloadMap)) if (isset($vnAutoloadMap))
foreach($vnAutoloadMap as $prefix => $location) { foreach ($vnAutoloadMap as $prefix => $location) {
$prefixLen = strlen($prefix); $prefixLen = strlen($prefix);
if (strncmp($classPath, $prefix, $prefixLen) == 0) { if (strncmp($classPath, $prefix, $prefixLen) == 0) {
@ -27,7 +27,7 @@ spl_autoload_register(function($className) {
} }
} }
if ($classPath{0} != DIRECTORY_SEPARATOR) if ($classPath{0} != '/')
$classPath = stream_resolve_include_path($classPath); $classPath = stream_resolve_include_path($classPath);
if (file_exists($classPath)) if (file_exists($classPath))