'.$msg.'
'; - if(!function_exists('debug_backtrace')) - return; - echo '';
- $index=-1;
- foreach(debug_backtrace() as $t)
- {
- $index++;
- if($index==0) // hide the backtrace of this function
- continue;
- echo '#'.$index.' ';
- if(isset($t['file']))
- echo basename($t['file']) . ':' . $t['line'];
- else
- echo '';
- echo ' -- ';
- if(isset($t['class']))
- echo $t['class'] . $t['type'];
- echo $t['function'] . '(';
- if(isset($t['args']) && sizeof($t['args']) > 0)
- {
- $count=0;
- foreach($t['args'] as $item)
- {
- if(is_string($item))
- {
- $str=htmlentities(str_replace("\r\n", "", $item), ENT_QUOTES);
- if (strlen($item) > 70)
- echo "'". substr($str, 0, 70) . "...'";
- else
- echo "'" . $str . "'";
- }
- else if (is_int($item) || is_float($item))
- echo $item;
- else if (is_object($item))
- echo get_class($item);
- else if (is_array($item))
- echo 'array(' . count($item) . ')';
- else if (is_bool($item))
- echo $item ? 'true' : 'false';
- else if ($item === null)
- echo 'NULL';
- else if (is_resource($item))
- echo get_resource_type($item);
- $count++;
- if (count($t['args']) > $count)
- echo ', ';
- }
- }
- echo ")\n";
- }
- echo ' ';
- exit(1);
- }
-
- /**
- * Returns a list of user preferred languages.
- * The languages are returned as an array. Each array element
- * represents a single language preference. The languages are ordered
- * according to user preferences. The first language is the most preferred.
- * @return array list of user preferred languages.
- */
- public static function getUserLanguages()
- {
- static $languages=null;
- if($languages===null)
- {
- if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
- $languages[0]='en';
- else
- {
- $languages=array();
- foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language)
- {
- $array=split(';q=',trim($language));
- $languages[trim($array[0])]=isset($array[1])?(float)$array[1]:1.0;
- }
- arsort($languages);
- $languages=array_keys($languages);
- if(empty($languages))
- $languages[0]='en';
- }
- }
- return $languages;
- }
-
- /**
- * Returns the most preferred language by the client user.
- * @return string the most preferred language by the client user, defaults to English.
- */
- public static function getPreferredLanguage()
- {
- static $language=null;
- if($language===null)
- {
- $langs=Prado::getUserLanguages();
- $lang=explode('-',$langs[0]);
- if(empty($lang[0]) || !ctype_alpha($lang[0]))
- $language='en';
- else
- $language=$lang[0];
- }
- return $language;
- }
-
- /**
- * Writes a log message.
- * This method wraps {@link log()} by checking the application mode.
- * When the application is in Debug mode, debug backtrace information is appended
- * to the message and the message is logged at DEBUG level.
- * When the application is in Performance mode, this method does nothing.
- * Otherwise, the message is logged at INFO level.
- * @param string message to be logged
- * @param string category of the message
- * @see log, getLogger
- */
- public static function trace($msg,$category='Uncategorized')
- {
- if(self::$_application && self::$_application->getMode()===TApplicationMode::Performance)
- return;
- if(!self::$_application || self::$_application->getMode()===TApplicationMode::Debug)
- {
- $trace=debug_backtrace();
- if(isset($trace[0]['file']) && isset($trace[0]['line']))
- $msg.=" (line {$trace[0]['line']}, {$trace[0]['file']})";
- $level=TLogger::DEBUG;
- }
- else
- $level=TLogger::INFO;
- self::log($msg,$level,$category);
- }
-
- /**
- * Logs a message.
- * Messages logged by this method may be retrieved via {@link TLogger::getLogs}
- * and may be recorded in different media, such as file, email, database, using
- * {@link TLogRouter}.
- * @param string message to be logged
- * @param integer level of the message. Valid values include
- * TLogger::DEBUG, TLogger::INFO, TLogger::NOTICE, TLogger::WARNING,
- * TLogger::ERROR, TLogger::ALERT, TLogger::FATAL.
- * @param string category of the message
- */
- public static function log($msg,$level=TLogger::INFO,$category='Uncategorized')
- {
- if(self::$_logger===null)
- self::$_logger=new TLogger;
- self::$_logger->log($msg,$level,$category);
- }
-
- /**
- * @return TLogger message logger
- */
- public static function getLogger()
- {
- if(self::$_logger===null)
- self::$_logger=new TLogger;
- return self::$_logger;
- }
-
- /**
- * Converts a variable into a string representation.
- * This method achieves the similar functionality as var_dump and print_r
- * but is more robust when handling complex objects such as PRADO controls.
- * @param mixed variable to be dumped
- * @param integer maximum depth that the dumper should go into the variable. Defaults to 10.
- * @param boolean whether to syntax highlight the output. Defaults to false.
- * @return string the string representation of the variable
- */
- public static function varDump($var,$depth=10,$highlight=false)
- {
- Prado::using('System.Util.TVarDumper');
- return TVarDumper::dump($var,$depth,$highlight);
- }
-
- /**
- * Localize a text to the locale/culture specified in the globalization handler.
- * @param string text to be localized.
- * @param array a set of parameters to substitute.
- * @param string a different catalogue to find the localize text.
- * @param string the input AND output charset.
- * @return string localized text.
- * @see TTranslate::formatter()
- * @see TTranslate::init()
- */
- public static function localize($text, $parameters=array(), $catalogue=null, $charset=null)
- {
- Prado::using('System.I18N.Translation');
- $app = Prado::getApplication()->getGlobalization(false);
-
- $params = array();
- foreach($parameters as $key => $value)
- $params['{'.$key.'}'] = $value;
-
- //no translation handler provided
- if($app===null || ($config = $app->getTranslationConfiguration())===null)
- return strtr($text, $params);
-
- if ($catalogue===null)
- $catalogue=isset($config['catalogue'])?$config['catalogue']:'messages';
-
- Translation::init($catalogue);
-
- //globalization charset
- $appCharset = $app===null ? '' : $app->getCharset();
-
- //default charset
- $defaultCharset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset();
-
- //fall back
- if(empty($charset)) $charset = $appCharset;
- if(empty($charset)) $charset = $defaultCharset;
-
- return Translation::formatter($catalogue)->format($text,$params,$catalogue,$charset);
- }
-}
-
-/**
- * TReflectionClass class.
- * This class was originally written to cope with the incompatibility between different PHP versions.
- * It is equivalent to ReflectionClass for PHP version >= 5.1.0
- * @author Qiang Xue '.$msg.'
'; + if(!function_exists('debug_backtrace')) + return; + echo '';
+ $index=-1;
+ foreach(debug_backtrace() as $t)
+ {
+ $index++;
+ if($index==0) // hide the backtrace of this function
+ continue;
+ echo '#'.$index.' ';
+ if(isset($t['file']))
+ echo basename($t['file']) . ':' . $t['line'];
+ else
+ echo '';
+ echo ' -- ';
+ if(isset($t['class']))
+ echo $t['class'] . $t['type'];
+ echo $t['function'] . '(';
+ if(isset($t['args']) && sizeof($t['args']) > 0)
+ {
+ $count=0;
+ foreach($t['args'] as $item)
+ {
+ if(is_string($item))
+ {
+ $str=htmlentities(str_replace("\r\n", "", $item), ENT_QUOTES);
+ if (strlen($item) > 70)
+ echo "'". substr($str, 0, 70) . "...'";
+ else
+ echo "'" . $str . "'";
+ }
+ else if (is_int($item) || is_float($item))
+ echo $item;
+ else if (is_object($item))
+ echo get_class($item);
+ else if (is_array($item))
+ echo 'array(' . count($item) . ')';
+ else if (is_bool($item))
+ echo $item ? 'true' : 'false';
+ else if ($item === null)
+ echo 'NULL';
+ else if (is_resource($item))
+ echo get_resource_type($item);
+ $count++;
+ if (count($t['args']) > $count)
+ echo ', ';
+ }
+ }
+ echo ")\n";
+ }
+ echo ' ';
+ exit(1);
+ }
+
+ /**
+ * Returns a list of user preferred languages.
+ * The languages are returned as an array. Each array element
+ * represents a single language preference. The languages are ordered
+ * according to user preferences. The first language is the most preferred.
+ * @return array list of user preferred languages.
+ */
+ public static function getUserLanguages()
+ {
+ static $languages=null;
+ if($languages===null)
+ {
+ if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
+ $languages[0]='en';
+ else
+ {
+ $languages=array();
+ foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $language)
+ {
+ $array=split(';q=',trim($language));
+ $languages[trim($array[0])]=isset($array[1])?(float)$array[1]:1.0;
+ }
+ arsort($languages);
+ $languages=array_keys($languages);
+ if(empty($languages))
+ $languages[0]='en';
+ }
+ }
+ return $languages;
+ }
+
+ /**
+ * Returns the most preferred language by the client user.
+ * @return string the most preferred language by the client user, defaults to English.
+ */
+ public static function getPreferredLanguage()
+ {
+ static $language=null;
+ if($language===null)
+ {
+ $langs=Prado::getUserLanguages();
+ $lang=explode('-',$langs[0]);
+ if(empty($lang[0]) || !ctype_alpha($lang[0]))
+ $language='en';
+ else
+ $language=$lang[0];
+ }
+ return $language;
+ }
+
+ /**
+ * Writes a log message.
+ * This method wraps {@link log()} by checking the application mode.
+ * When the application is in Debug mode, debug backtrace information is appended
+ * to the message and the message is logged at DEBUG level.
+ * When the application is in Performance mode, this method does nothing.
+ * Otherwise, the message is logged at INFO level.
+ * @param string message to be logged
+ * @param string category of the message
+ * @see log, getLogger
+ */
+ public static function trace($msg,$category='Uncategorized')
+ {
+ if(self::$_application && self::$_application->getMode()===TApplicationMode::Performance)
+ return;
+ if(!self::$_application || self::$_application->getMode()===TApplicationMode::Debug)
+ {
+ $trace=debug_backtrace();
+ if(isset($trace[0]['file']) && isset($trace[0]['line']))
+ $msg.=" (line {$trace[0]['line']}, {$trace[0]['file']})";
+ $level=TLogger::DEBUG;
+ }
+ else
+ $level=TLogger::INFO;
+ self::log($msg,$level,$category);
+ }
+
+ /**
+ * Logs a message.
+ * Messages logged by this method may be retrieved via {@link TLogger::getLogs}
+ * and may be recorded in different media, such as file, email, database, using
+ * {@link TLogRouter}.
+ * @param string message to be logged
+ * @param integer level of the message. Valid values include
+ * TLogger::DEBUG, TLogger::INFO, TLogger::NOTICE, TLogger::WARNING,
+ * TLogger::ERROR, TLogger::ALERT, TLogger::FATAL.
+ * @param string category of the message
+ */
+ public static function log($msg,$level=TLogger::INFO,$category='Uncategorized')
+ {
+ if(self::$_logger===null)
+ self::$_logger=new TLogger;
+ self::$_logger->log($msg,$level,$category);
+ }
+
+ /**
+ * @return TLogger message logger
+ */
+ public static function getLogger()
+ {
+ if(self::$_logger===null)
+ self::$_logger=new TLogger;
+ return self::$_logger;
+ }
+
+ /**
+ * Converts a variable into a string representation.
+ * This method achieves the similar functionality as var_dump and print_r
+ * but is more robust when handling complex objects such as PRADO controls.
+ * @param mixed variable to be dumped
+ * @param integer maximum depth that the dumper should go into the variable. Defaults to 10.
+ * @param boolean whether to syntax highlight the output. Defaults to false.
+ * @return string the string representation of the variable
+ */
+ public static function varDump($var,$depth=10,$highlight=false)
+ {
+ Prado::using('System.Util.TVarDumper');
+ return TVarDumper::dump($var,$depth,$highlight);
+ }
+
+ /**
+ * Localize a text to the locale/culture specified in the globalization handler.
+ * @param string text to be localized.
+ * @param array a set of parameters to substitute.
+ * @param string a different catalogue to find the localize text.
+ * @param string the input AND output charset.
+ * @return string localized text.
+ * @see TTranslate::formatter()
+ * @see TTranslate::init()
+ */
+ public static function localize($text, $parameters=array(), $catalogue=null, $charset=null)
+ {
+ Prado::using('System.I18N.Translation');
+ $app = Prado::getApplication()->getGlobalization(false);
+
+ $params = array();
+ foreach($parameters as $key => $value)
+ $params['{'.$key.'}'] = $value;
+
+ //no translation handler provided
+ if($app===null || ($config = $app->getTranslationConfiguration())===null)
+ return strtr($text, $params);
+
+ if ($catalogue===null)
+ $catalogue=isset($config['catalogue'])?$config['catalogue']:'messages';
+
+ Translation::init($catalogue);
+
+ //globalization charset
+ $appCharset = $app===null ? '' : $app->getCharset();
+
+ //default charset
+ $defaultCharset = ($app===null) ? 'UTF-8' : $app->getDefaultCharset();
+
+ //fall back
+ if(empty($charset)) $charset = $appCharset;
+ if(empty($charset)) $charset = $defaultCharset;
+
+ return Translation::formatter($catalogue)->format($text,$params,$catalogue,$charset);
+ }
+}
+
+/**
+ * TReflectionClass class.
+ * This class was originally written to cope with the incompatibility between different PHP versions.
+ * It is equivalent to ReflectionClass for PHP version >= 5.1.0
+ * @author Qiang Xue Version 3.1.3, November 1, 2008
+
Version 3.1.4, To be released
Copyright© 2004-2008 by Prado Software
All Rights Reserved.