autoloader update, config master, db io minor fixes

Various not needed isset checks removed
autoloader correctly checks that "LIB" is at the end of the path only
This commit is contained in:
Clemens Schwaighofer
2019-09-19 18:54:46 +09:00
parent 4508692330
commit 8ade113070
5 changed files with 22 additions and 21 deletions

View File

@@ -23,7 +23,7 @@ if (!defined('SET_SESSION_NAME')) {
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
}
// define log file id
define('LOG_FILE_ID', 'classTest');
$LOG_FILE_ID = 'classTest';
// set language for l10n
$lang = 'en_utf8';

View File

@@ -194,14 +194,13 @@ list($HOST_NAME) = array_pad(explode(':', $_SERVER['HTTP_HOST'], 2), 2, null);
// we have either no db selction for this host but have db config entries
// or we have a db selection but no db config as array or empty
// or we have a selection but no matching db config entry
if ((!isset($SITE_CONFIG[$HOST_NAME]['db_host']) && isset($DB_CONFIG) && count($DB_CONFIG)) ||
if ((!isset($SITE_CONFIG[$HOST_NAME]['db_host']) && count($DB_CONFIG)) ||
(isset($SITE_CONFIG[$HOST_NAME]['db_host']) &&
// missing DB CONFIG
(!isset($DB_CONFIG)) ||
(isset($DB_CONFIG) && is_array($DB_CONFIG) && !count($DB_CONFIG)) ||
(isset($DB_CONFIG) && !is_array($DB_CONFIG)) ||
((is_array($DB_CONFIG) && !count($DB_CONFIG)) ||
!is_array($DB_CONFIG) ||
// has DB CONFIG but no match
(isset($DB_CONFIG) && is_array($DB_CONFIG) && count($DB_CONFIG) && !isset($DB_CONFIG[$SITE_CONFIG[$HOST_NAME]['db_host']]))
(is_array($DB_CONFIG) && count($DB_CONFIG) && !isset($DB_CONFIG[$SITE_CONFIG[$HOST_NAME]['db_host']])))
)
) {
echo 'No matching DB config found for: "'.$HOST_NAME.'". Contact Administrator';

View File

@@ -95,9 +95,8 @@
namespace CoreLibs;
// define check vars for the flags we can have
/** @internal */
define('CLASS_STRICT_MODE', 1);
define('CLASS_OFF_COMPATIBLE_MODE', 2);
const CLASS_STRICT_MODE = 1;
const CLASS_OFF_COMPATIBLE_MODE = 2;
/** Basic core class declaration */
class Basic

View File

@@ -1915,19 +1915,19 @@ class IO extends \CoreLibs\Basic
{
switch ($kbn) {
case 'i':
$value = (!isset($value) || $value === '') ? "NULL" : intval($value);
$value = ($value === '') ? "NULL" : intval($value);
break;
case 'f':
$value = (!isset($value) || $value === '') ? "NULL" : floatval($value);
$value = ($value === '') ? "NULL" : floatval($value);
break;
case 't':
$value = (!isset($value) || $value === '') ? "NULL" : "'".$this->dbEscapeString($value)."'";
$value = ($value === '') ? "NULL" : "'".$this->dbEscapeString($value)."'";
break;
case 'd':
$value = (!isset($value) || $value === '') ? "NULL" : "'".$this->dbEscapeString($value)."'";
$value = ($value === '') ? "NULL" : "'".$this->dbEscapeString($value)."'";
break;
case 'i2':
$value = (!isset($value) || $value === '') ? 0 : intval($value);
$value = ($value === '') ? 0 : intval($value);
break;
}
return $value;

View File

@@ -15,12 +15,15 @@ if (class_exists('Autoload', false) === false) {
{
// print "(1) Class: $class / DIR: ".__DIR__."<br>";
// set directory seperator (we need to replace from namespace)
$ds = defined('DS') ? DS : DIRECTORY_SEPARATOR;
$DS = defined('DS') ? DS : DIRECTORY_SEPARATOR;
// base lib
$LIB = defined('LIB') ? LIB : 'lib';
// if lib is in path, do not add lib again
if (strpos(__DIR__, $LIB) !== false) {
$LIB .= $ds;
$LIB = defined('LIB') ? LIB : 'lib'.$DS;
// if lib is in path at the end, do not add lib again
// note that $LIB can have a directory seperator at the end
// strip that out before we do a match
$_LIB = rtrim($LIB, $DS);
if (preg_match("|$_LIB$|", __DIR__) === false) {
$LIB .= $DS;
} else {
$LIB = '';
}
@@ -35,9 +38,9 @@ if (class_exists('Autoload', false) === false) {
// set default extension
$extension = '.php';
// set full include path
$path = __DIR__.$ds.$LIB.substr($class, $len);
$path = __DIR__.$DS.$LIB.substr($class, $len);
// replace namespace \ with dir sepeator
$path = str_replace('\\', $ds, $path).$extension;
$path = str_replace('\\', $DS, $path).$extension;
// print "(2) Class clean: $path<br>";
// if path is set and a valid file
if ($path !== false && is_file($path)) {