Index: branches/5.2.x/core/kernel/application.php
===================================================================
diff -u -N -r14588 -r14596
--- branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14588)
+++ branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14596)
@@ -1,6 +1,6 @@
*
* The class is a singleton, which means that there could be only one instance of kApplication in the script.
-* This could be guranteed by NOT calling the class constuctor directly, but rather calling kApplication::Instance() method,
-* which returns an instance of the application. The method gurantees that it will return exactly the same instance for any call.
+* This could be guaranteed by NOT calling the class constructor directly, but rather calling kApplication::Instance() method,
+* which returns an instance of the application. The method guarantees that it will return exactly the same instance for any call.
* See singleton pattern by GOF.
*/
class kApplication implements kiCacheable {
@@ -187,8 +187,8 @@
var $cacheManager = null;
/**
- * Tells, that administrator has authentificated in administrative console
- * Should be used to manipulate data change OR data restrictioning!
+ * Tells, that administrator has authenticated in administrative console
+ * Should be used to manipulate data change OR data restrictions!
*
* @var bool
*/
@@ -222,7 +222,7 @@
* Returns kApplication instance anywhere in the script.
*
* This method should be used to get single kApplication object instance anywhere in the
- * Kernel-based application. The method is guranteed to return the SAME instance of kApplication.
+ * Kernel-based application. The method is guaranteed to return the SAME instance of kApplication.
* Anywhere in the script you could write:
*
* $application =& kApplication::Instance();
@@ -232,7 +232,7 @@
* $this->Application =& kApplication::Instance();
*
* to get the instance of kApplication. Note that we call the Instance method as STATIC - directly from the class.
- * To use descendand of standard kApplication class in your project you would need to define APPLICATION_CLASS constant
+ * To use descendant of standard kApplication class in your project you would need to define APPLICATION_CLASS constant
* BEFORE calling kApplication::Instance() for the first time. If APPLICATION_CLASS is not defined the method would
* create and return default KernelApplication instance.
*
@@ -266,7 +266,7 @@
*/
public function Init()
{
- if($this->InitDone) {
+ if ( $this->InitDone ) {
return false;
}
@@ -276,24 +276,24 @@
ob_start(); // collect any output from method (other then tags) into buffer
}
- if (defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY')) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY') ) {
$this->Debugger->appendMemoryUsage('Application before Init:');
}
- if (!$this->isDebugMode() && !kUtil::constOn('DBG_ZEND_PRESENT')) {
+ if ( !$this->isDebugMode() && !kUtil::constOn('DBG_ZEND_PRESENT') ) {
error_reporting(0);
ini_set('display_errors', 0);
}
- if (!kUtil::constOn('DBG_ZEND_PRESENT')) {
- $error_handler = set_error_handler( Array (&$this, 'handleError') );
- if ($error_handler) {
+ if ( !kUtil::constOn('DBG_ZEND_PRESENT') ) {
+ $error_handler = set_error_handler(Array (&$this, 'handleError'));
+ if ( $error_handler ) {
// wrap around previous error handler, if any was set
$this->errorHandlers[] = $error_handler;
}
- $exception_handler = set_exception_handler( Array (&$this, 'handleException') );
- if ($exception_handler) {
+ $exception_handler = set_exception_handler(Array (&$this, 'handleException'));
+ if ( $exception_handler ) {
// wrap around previous exception handler, if any was set
$this->exceptionHandlers[] = $exception_handler;
}
@@ -302,14 +302,14 @@
$this->Factory = new kFactory();
$this->registerDefaultClasses();
- $this->Conn =& $this->Factory->makeClass( 'kDBConnection', Array (SQL_TYPE, Array (&$this, 'handleSQLError')) );
+ $this->Conn =& $this->Factory->makeClass('kDBConnection', Array (SQL_TYPE, Array (&$this, 'handleSQLError')));
$this->Conn->debugMode = $this->isDebugMode();
$this->Conn->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB);
$this->cacheManager =& $this->makeClass('kCacheManager');
$this->cacheManager->InitCache();
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendTimestamp('Before UnitConfigReader');
}
@@ -318,27 +318,27 @@
$this->registerModuleConstants();
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendTimestamp('After UnitConfigReader');
}
define('MOD_REWRITE', $this->ConfigValue('UseModRewrite') && !$this->isAdmin ? 1 : 0);
$this->HttpQuery =& $this->recallObject('HTTPQuery');
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendTimestamp('Processed HTTPQuery initial');
}
$this->Session =& $this->recallObject('Session');
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendTimestamp('Processed Session');
}
- if (!$this->RecallVar('UserGroups')) {
+ if ( !$this->RecallVar('UserGroups') ) {
$user_groups = trim($this->Session->GetField('GroupList'), ',');
- if (!$user_groups) {
+ if ( !$user_groups ) {
$user_groups = $this->ConfigValue('User_GuestGroup');
}
@@ -351,57 +351,59 @@
$this->Session->ValidateExpired();
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendTimestamp('Processed HTTPQuery AfterInit');
}
$this->cacheManager->LoadApplicationCache();
$site_timezone = $this->ConfigValue('Config_Site_Time');
- if ($site_timezone) {
+ if ( $site_timezone ) {
putenv('TZ=' . $site_timezone);
}
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendTimestamp('Loaded cache and phrases');
}
$this->ValidateLogin(); // must be called before AfterConfigRead, because current user should be available there
$this->UnitConfigReader->AfterConfigRead();
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendTimestamp('Processed AfterConfigRead');
}
- if ($this->GetVar('m_cat_id') === false) {
+ if ( $this->GetVar('m_cat_id') === false ) {
$this->SetVar('m_cat_id', 0);
}
- if (!$this->RecallVar('curr_iso')) {
+ if ( !$this->RecallVar('curr_iso') ) {
$this->StoreVar('curr_iso', $this->GetPrimaryCurrency(), true); // true for optional
}
$visit_id = $this->RecallVar('visit_id');
- if ($visit_id !== false) {
+ if ( $visit_id !== false ) {
$this->SetVar('visits_id', $visit_id);
}
- $language =& $this->recallObject( 'lang.current', null, Array('live_table' => true) );
- if (preg_match('/utf-8/', $language->GetDBField('Charset'))) {
+ $language =& $this->recallObject('lang.current', null, Array ('live_table' => true));
+ /* @var $language LanguagesItem */
+
+ if ( preg_match('/utf-8/', $language->GetDBField('Charset')) ) {
setlocale(LC_ALL, 'en_US.UTF-8');
mb_internal_encoding('UTF-8');
}
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->profileFinish('kernel4_startup');
}
$this->InitDone = true;
- $this->HandleEvent( new kEvent('adm:OnStartup') );
+ $this->HandleEvent(new kEvent('adm:OnStartup'));
return true;
}
@@ -446,11 +448,17 @@
return false;
}
- function refreshModuleInfo()
+ /**
+ * Refreshes information about loaded modules
+ *
+ * @return void
+ * @access public
+ */
+ public function refreshModuleInfo()
{
if (defined('IS_INSTALL') && IS_INSTALL && !$this->TableFound('Modules')) {
$this->registerModuleConstants();
- return false;
+ return ;
}
$modules_helper =& $this->makeClass('ModulesHelper');
@@ -519,21 +527,30 @@
function GetFrontThemePath($force=0)
{
- static $path=null;
- if (!$force && isset($path)) return $path;
+ static $path = null;
+ if ( !$force && isset($path) ) {
+ return $path;
+ }
+
$theme_id = $this->GetVar('m_theme');
- if (!$theme_id) {
+ if ( !$theme_id ) {
// $theme_id = $this->GetDefaultThemeId(1); //1 to force front-end mode!
$theme_id = 'default';
}
+
$this->SetVar('m_theme', $theme_id);
- $this->SetVar('theme.current_id', $theme_id ); // KOSTJA: this is to fool theme' getPassedId
+ $this->SetVar('theme.current_id', $theme_id); // KOSTJA: this is to fool theme' getPassedId
$theme =& $this->recallObject('theme.current');
- if (!$theme->IsLoaded() || !$theme->GetDBField('Enabled')) {
+ /* @var $theme ThemeItem */
+
+ if ( !$theme->isLoaded() || !$theme->GetDBField('Enabled') ) {
return false;
}
- $path = '/themes/'.$theme->GetDBField('Name');
+
+ // assign & then return, since it's static variable
+ $path = '/themes/' . $theme->GetDBField('Name');
+
return $path;
}
@@ -685,6 +702,7 @@
$this->registerClass('kCacheManager', KERNEL_PATH . '/managers/cache_manager.php', null, 'kiCacheable');
$this->registerClass('PhrasesCache', KERNEL_PATH . '/languages/phrases_cache.php', 'kPhraseCache');
$this->registerClass('kTempTablesHandler', KERNEL_PATH . '/utility/temp_handler.php');
+ $this->registerClass('kValidator', KERNEL_PATH . '/utility/validator.php');
$this->registerClass('kUnitConfigReader', KERNEL_PATH . '/utility/unit_config_reader.php');
@@ -948,7 +966,10 @@
elseif ($this->GetVar('admin')) {
// viewing front-end through admin's frame
$admin_session =& $this->recallObject('Session.admin');
+ /* @var $admin_session Session */
+
$user = (int)$admin_session->RecallVar('user_id'); // in case, when no valid admin session found
+
$perm_helper =& $this->recallObject('PermissionsHelper');
/* @var $perm_helper kPermissionsHelper */
@@ -1172,29 +1193,34 @@
/**
* Returns current session id (SID)
* @access public
- * @return longint
+ * @return int
*/
function GetSID()
{
$session =& $this->recallObject('Session');
+ /* @var $session Session */
+
return $session->GetID();
}
function DestroySession()
{
$session =& $this->recallObject('Session');
+ /* @var $session Session */
+
$session->Destroy();
}
/**
- * Returns variable passed to the script as GET/POST/COOKIE
- *
- * @access public
- * @param string $name Name of variable to retrieve
- * @param int $default default value returned in case if varible not present
- * @return mixed
- */
- function GetVar($name, $default = false)
+ * Returns variable passed to the script as GET/POST/COOKIE
+ *
+ * @param string $name Name of variable to retrieve
+ * @param mixed $default default value returned in case if variable not present
+ *
+ * @return mixed
+ * @access public
+ */
+ public function GetVar($name, $default = false)
{
return isset($this->HttpQuery->_Params[$name]) ? $this->HttpQuery->_Params[$name] : $default;
}
@@ -1223,9 +1249,9 @@
* @access public
* @return void
*/
- function SetVar($var,$val)
+ public function SetVar($var,$val)
{
- return $this->HttpQuery->Set($var, $val);
+ $this->HttpQuery->Set($var, $val);
}
/**
@@ -1355,14 +1381,10 @@
return $this->GetVar($var);
}
- function AddBlock($name, $tpl)
- {
- $this->cache[$name] = $tpl;
- }
-
function ProcessParsedTag($prefix, $tag, $params)
{
$processor = $this->Parser->GetProcessor($prefix);
+ /* @var $processor kDBTagProcessor */
return $processor->ProcessParsedTag($tag, $params, $prefix);
}
@@ -1446,7 +1468,7 @@
return $this->UrlManager->getPassThroughVariables($params);
}
- function BuildEnv($t, $params, $pass='all', $pass_events = false, $env_var = true)
+ function BuildEnv($t, $params, $pass = 'all', $pass_events = false, $env_var = true)
{
return $this->UrlManager->BuildEnv($t, $params, $pass, $pass_events, $env_var);
}
@@ -1599,15 +1621,17 @@
function ValidateLogin()
{
$session =& $this->recallObject('Session');
+ /* @var $session Session */
+
$user_id = $session->GetField('PortalUserId');
- if (!$user_id && $user_id != USER_ROOT) {
+ if ( !$user_id && $user_id != USER_ROOT ) {
$user_id = USER_GUEST;
}
$this->SetVar('u.current_id', $user_id);
- if (!$this->isAdmin) {
+ if ( !$this->isAdmin ) {
// needed for "profile edit", "registration" forms ON FRONT ONLY
$this->SetVar('u_id', $user_id);
}
@@ -1616,18 +1640,19 @@
$this->isAdminUser = $this->isAdmin && $this->LoggedIn();
- if ($this->GetVar('expired') == 1) {
+ if ( $this->GetVar('expired') == 1 ) {
// this parameter is set only from admin
$user =& $this->recallObject('u.current');
+ /* @var $user UsersItem */
+
$user->SetError('ValidateLogin', 'session_expired', 'la_text_sess_expired');
}
- if (($user_id != USER_GUEST) && kUtil::constOn('DBG_REQUREST_LOG') ) {
- $http_query =& $this->recallObject('HTTPQuery');
- $http_query->writeRequestLog(DBG_REQUREST_LOG);
+ if ( ($user_id != USER_GUEST) && defined('DBG_REQUREST_LOG') && DBG_REQUREST_LOG ) {
+ $this->HttpQuery->writeRequestLog(DBG_REQUREST_LOG);
}
- if ($user_id != USER_GUEST) {
+ if ( $user_id != USER_GUEST ) {
// normal users + root
$this->LoadPersistentVars();
}
@@ -2009,21 +2034,23 @@
* @param string $errfile
* @param int $errline
* @param Array $errcontext
+ * @return bool
+ * @access public
*/
- function handleError($errno, $errstr = '', $errfile = '', $errline = '', $errcontext = '')
+ public function handleError($errno, $errstr, $errfile = null, $errline = null, $errcontext = Array ())
{
$this->errorLogSilent($errno, $errstr, $errfile, $errline);
$debug_mode = defined('DEBUG_MODE') && DEBUG_MODE;
$skip_reporting = defined('DBG_SKIP_REPORTING') && DBG_SKIP_REPORTING;
- if (!$this->errorHandlers || ($debug_mode && $skip_reporting)) {
+ if ( !$this->errorHandlers || ($debug_mode && $skip_reporting) ) {
// when debugger absent OR it's present, but we actually can't see it's error report (e.g. during ajax request)
- if ($errno == E_USER_ERROR) {
+ if ( $errno == E_USER_ERROR ) {
$this->errorDisplayFatal('Fatal Error: ' . "{$errstr} in {$errfile} on line {$errline}");
}
- if (!$this->errorHandlers) {
+ if ( !$this->errorHandlers ) {
return true;
}
}
@@ -2049,8 +2076,9 @@
*
* @param Exception $exception
* @return bool
+ * @access public
*/
- function handleException($exception)
+ public function handleException($exception)
{
// transform exception to regular error (no need to rewrite existing error handlers)
$errno = $exception->getCode();
@@ -2063,11 +2091,11 @@
$debug_mode = defined('DEBUG_MODE') && DEBUG_MODE;
$skip_reporting = defined('DBG_SKIP_REPORTING') && DBG_SKIP_REPORTING;
- if (!$this->exceptionHandlers || ($debug_mode && $skip_reporting)) {
+ if ( !$this->exceptionHandlers || ($debug_mode && $skip_reporting) ) {
// when debugger absent OR it's present, but we actually can't see it's error report (e.g. during ajax request)
$this->errorDisplayFatal('' . get_class($exception) . ': ' . "{$errstr} in {$errfile} on line {$errline}");
- if (!$this->exceptionHandlers) {
+ if ( !$this->exceptionHandlers ) {
return true;
}
}
@@ -2088,10 +2116,19 @@
return $res;
}
- protected function errorLogSilent($errno, $errstr = '', $errfile = '', $errline = '')
+ /**
+ * Silently saves each given error message to "silent_log.txt" file, when silent log mode is enabled
+ * @param int $errno
+ * @param string $errstr
+ * @param string $errfile
+ * @param int $errline
+ * @return void
+ * @access protected
+ */
+ protected function errorLogSilent($errno, $errstr = '', $errfile = '', $errline = null)
{
- if (!defined('SILENT_LOG') || !SILENT_LOG) {
- return ;
+ if ( !defined('SILENT_LOG') || !SILENT_LOG ) {
+ return;
}
if ( !(defined('DBG_IGNORE_STRICT_ERRORS') && DBG_IGNORE_STRICT_ERRORS && defined('E_STRICT') && ($errno == E_STRICT)) ) {
@@ -2103,6 +2140,13 @@
}
}
+ /**
+ * Displays div with given error message
+ *
+ * @param string $msg
+ * @return void
+ * @access protected
+ */
protected function errorDisplayFatal($msg)
{
$margin = $this->isAdmin ? '8px' : 'auto';
@@ -2116,8 +2160,9 @@
* @param bool $return_result
* @param int $skip_levels
* @return string
+ * @access public
*/
- function printTrace($return_result = false, $skip_levels = 1)
+ public function printTrace($return_result = false, $skip_levels = 1)
{
$ret = Array ();
$trace = debug_backtrace(false);
@@ -2127,11 +2172,11 @@
}
foreach ($trace as $level => $trace_info) {
- if ( isset($trace_info['class']) ) {
+ if ( isset($trace_info['class']) ) {
$object = $trace_info['class'];
}
elseif ( isset($trace_info['object']) ) {
- $object = get_class( $trace_info['object'] );
+ $object = get_class($trace_info['object']);
}
else {
$object = '';
@@ -2153,14 +2198,16 @@
$args = substr($args, 0, -2);
}
- $ret[] = '#' . $level . ' ' . $object . $type . $trace_info['function']. '(' . $args . ') called at [' . $trace_info['file'] . ':' . $trace_info['line'] . ']';
+ $ret[] = '#' . $level . ' ' . $object . $type . $trace_info['function'] . '(' . $args . ') called at [' . $trace_info['file'] . ':' . $trace_info['line'] . ']';
}
- if ($return_result) {
+ if ( $return_result ) {
return implode("\n", $ret);
}
echo implode("\n", $ret);
+
+ return '';
}
/**
@@ -2556,35 +2603,40 @@
}
/**
- * Resets counter, whitch are affected by one of specified tables
+ * Resets counter, which are affected by one of specified tables
*
* @param string $tables comma separated tables list used in counting sqls
+ * @return void
+ * @access public
*/
- function resetCounters($tables)
+ public function resetCounters($tables)
{
- if (kUtil::constOn('IS_INSTALL')) {
- return ;
+ if ( kUtil::constOn('IS_INSTALL') ) {
+ return;
}
$count_helper =& $this->recallObject('CountHelper');
/* @var $count_helper kCountHelper */
- return $count_helper->resetCounters($tables);
+ $count_helper->resetCounters($tables);
}
/**
* Sends XML header + optionally displays xml heading
*
- * @param string $xml_version
+ * @param string|bool $xml_version
* @return string
+ * @access public
* @author Alex
*/
- function XMLHeader($xml_version = false)
+ public function XMLHeader($xml_version = false)
{
$lang =& $this->recallObject('lang.current');
- header('Content-type: text/xml; charset='.$lang->GetDBField('Charset'));
+ /* @var $lang LanguagesItem */
- return $xml_version ? 'GetDBField('Charset').'"?>' : '';
+ header('Content-type: text/xml; charset=' . $lang->GetDBField('Charset'));
+
+ return $xml_version ? 'GetDBField('Charset') . '"?>' : '';
}
/**