function meth_Misc_UserFctCheck(&$FctInfo, &$ErrMsg, $DataFct) { $Ref = $FctInfo[0] === '~'; if (isset($this->_UserFctLst[$FctInfo])) { if ($Ref) { $FctInfo = $this->_UserFctLst[$FctInfo]; } return true; } $FctStr = $FctInfo; if ($Ref) { $ObjRef =& $this->ObjectRef; $Lst = explode('.', substr($FctStr, 1)); $iMax = count($Lst) - 1; $Suff = 'tbsdb'; $iMax0 = $iMax; if ($DataFct) { $Suff = $Lst[$iMax]; $iMax--; } // Reading sub items for ($i = 0; $i <= $iMax; $i++) { $x =& $Lst[$i]; if (is_object($ObjRef)) { $ArgLst = tbs_Misc_CheckArgLst($x); if (method_exists($ObjRef, $x)) { if ($i < $iMax) { $f = array(&$ObjRef, $x); unset($ObjRef); $ObjRef = call_user_func_array($f, $ArgLst); } } elseif ($i === $iMax0) { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because \'' . $x . '\' is not a method in the class \'' . get_class($ObjRef) . '\'.'; return false; } elseif (isset($ObjRef->{$x})) { $ObjRef =& $ObjRef->{$x}; } else { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because sub-item \'' . $x . '\' is neither a method nor a property in the class \'' . get_class($ObjRef) . '\'.'; return false; } } elseif ($i < $iMax0 and is_array($ObjRef)) { if (isset($ObjRef[$x])) { $ObjRef =& $ObjRef[$x]; } else { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because sub-item \'' . $x . '\' is not a existing key in the array.'; return false; } } else { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because ' . ($i === 0 ? 'property ObjectRef' : 'sub-item \'' . $x . '\'') . ' is not an object' . ($i < $iMax ? ' or an array.' : '.'); return false; } } // Referencing last item if ($DataFct) { $FctInfo = array(0 => 'open', 1 => 'fetch', 2 => 'close'); foreach ($FctInfo as $i => $x) { $FctName = $Suff . '_' . $x; if (method_exists($ObjRef, $FctName)) { $FctInfo[$i] = array(&$ObjRef, $FctName); } else { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because method ' . $FctName . ' is not found.'; return false; } } } else { $FctInfo = array(&$ObjRef, $x); } $this->_UserFctLst[$FctStr] =& $FctInfo; } else { if (!function_exists($FctStr)) { $x = explode('.', $FctStr); if (count($x) == 2) { if (class_exists($x[0])) { $FctInfo = $x; } else { $ErrMsg = 'user function \'' . $FctStr . '\' is not correct because \'' . $x[0] . '\' is not a class name.'; return false; } } else { $ErrMsg = 'user function \'' . $FctStr . '\' is not found.'; return false; } } $this->_UserFctLst[$FctStr] = true; } return true; }
function meth_Misc_UserFctCheck(&$FctInfo, $FctCat, &$FctObj, &$ErrMsg) { $FctId = $FctCat . ':' . $FctInfo; if (isset($this->_UserFctLst[$FctId])) { $FctInfo = $this->_UserFctLst[$FctId]; return true; } // Check and put in cache $FctStr = $FctInfo; $IsData = $FctCat !== 'f'; $Save = true; if ($FctStr[0] === '~') { $ObjRef =& $this->ObjectRef; $Lst = explode('.', substr($FctStr, 1)); $iMax = count($Lst) - 1; $Suff = 'tbsdb'; $iMax0 = $iMax; if ($IsData) { $Suff = $Lst[$iMax]; $iMax--; } // Reading sub items for ($i = 0; $i <= $iMax; $i++) { $x =& $Lst[$i]; if (is_object($ObjRef)) { $ArgLst = tbs_Misc_CheckArgLst($x); if (method_exists($ObjRef, $x)) { if ($i < $iMax) { $f = array(&$ObjRef, $x); unset($ObjRef); $ObjRef = call_user_func_array($f, $ArgLst); } } elseif ($i === $iMax0) { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because \'' . $x . '\' is not a method in the class \'' . get_class($ObjRef) . '\'.'; return false; } elseif (isset($ObjRef->{$x})) { $ObjRef =& $ObjRef->{$x}; } else { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because sub-item \'' . $x . '\' is neither a method nor a property in the class \'' . get_class($ObjRef) . '\'.'; return false; } } elseif ($i < $iMax0 and is_array($ObjRef)) { if (isset($ObjRef[$x])) { $ObjRef =& $ObjRef[$x]; } else { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because sub-item \'' . $x . '\' is not a existing key in the array.'; return false; } } else { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because ' . ($i === 0 ? 'property ObjectRef' : 'sub-item \'' . $x . '\'') . ' is not an object' . ($i < $iMax ? ' or an array.' : '.'); return false; } } // Referencing last item if ($IsData) { $FctInfo = array('open' => '', 'fetch' => '', 'close' => ''); foreach ($FctInfo as $act => $x) { $FctName = $Suff . '_' . $act; if (method_exists($ObjRef, $FctName)) { $FctInfo[$act] = array(&$ObjRef, $FctName); } else { $ErrMsg = 'Expression \'' . $FctStr . '\' is invalid because method ' . $FctName . ' is not found.'; return false; } } $FctInfo['type'] = 4; if (isset($this->RecheckObj) and $this->RecheckObj) { $Save = false; } } else { $FctInfo = array(&$ObjRef, $x); } } elseif ($IsData) { $IsObj = $FctCat === 'o'; if ($IsObj and method_exists($FctObj, 'tbsdb_open') and !method_exists($FctObj, '+')) { // '+' avoid a bug in PHP 5 if (!method_exists($FctObj, 'tbsdb_fetch')) { $ErrMsg = 'the expected method \'tbsdb_fetch\' is not found for the class ' . $Cls . '.'; return false; } if (!method_exists($FctObj, 'tbsdb_close')) { $ErrMsg = 'the expected method \'tbsdb_close\' is not found for the class ' . $Cls . '.'; return false; } $FctInfo = array('type' => 5); } else { if ($FctCat === 'r') { // Resource $x = strtolower($FctStr); $x = str_replace('-', '_', $x); $Key = ''; $i = 0; $iMax = strlen($x); while ($i < $iMax) { if ($x[$i] === '_' or $x[$i] >= 'a' and $x[$i] <= 'z' or $x[$i] >= '0' and $x[$i] <= '9') { $Key .= $x[$i]; $i++; } else { $i = $iMax; } } } else { $Key = $FctStr; } $FctInfo = array('open' => '', 'fetch' => '', 'close' => ''); foreach ($FctInfo as $act => $x) { $FctName = 'tbsdb_' . $Key . '_' . $act; if (function_exists($FctName)) { $FctInfo[$act] = $FctName; } else { $err = true; if ($act === 'open') { // Try simplified key $p = strpos($Key, '_'); if ($p !== false) { $Key2 = substr($Key, 0, $p); $FctName2 = 'tbsdb_' . $Key2 . '_' . $act; if (function_exists($FctName2)) { $err = false; $Key = $Key2; $FctInfo[$act] = $FctName2; } } } if ($err) { $ErrMsg = 'Data source Id \'' . $FctStr . '\' is unsupported because function \'' . $FctName . '\' is not found.'; return false; } } } $FctInfo['type'] = 3; } } else { if (!function_exists($FctStr)) { $x = explode('.', $FctStr); if (count($x) == 2) { if (class_exists($x[0])) { $FctInfo = $x; } else { $ErrMsg = 'user function \'' . $FctStr . '\' is not correct because \'' . $x[0] . '\' is not a class name.'; return false; } } else { $ErrMsg = 'user function \'' . $FctStr . '\' is not found.'; return false; } } } if ($Save) { $this->_UserFctLst[$FctId] = $FctInfo; } return true; }