@ -1,15 +1,20 @@
<?php
<?php
/**
namespace yii;
* YiiBase class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/**
/**
* This constant defines the application start timestamp.
* Get s the application start timestamp.
*/
*/
defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME', microtime(true));
defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME', microtime(true));
/**
/**
* This constant defines whether the application should be in debug mode or not. Defaults to false.
* This constant defines whether the application should be in debug mode or not. Defaults to false.
*/
*/
defined('YII_DEBUG') or define('YII_DEBUG',false);
defined('YII_DEBUG') or define('YII_DEBUG', false);
/**
/**
* This constant defines how much call stack information (file name and line number) should be logged by Yii::trace().
* This constant defines how much call stack information (file name and line number) should be logged by Yii::trace().
* Defaults to 0, meaning no backtrace information. If it is greater than 0,
* Defaults to 0, meaning no backtrace information. If it is greater than 0,
@ -19,120 +24,88 @@ defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 0);
/**
/**
* This constant defines whether exception handling should be enabled. Defaults to true.
* This constant defines whether exception handling should be enabled. Defaults to true.
*/
*/
defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER',true);
defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER', true);
/**
/**
* This constant defines whether error handling should be enabled. Defaults to true.
* This constant defines whether error handling should be enabled. Defaults to true.
*/
*/
defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER',true);
defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER', true);
/**
/**
* Defines the Yii framework installation path.
* Defines the Yii framework installation path.
*/
*/
defined('YII_PATH') or define('YII_PATH',dirname(__FILE__));
defined('YII_PATH') or define('YII_PATH', __DIR__);
/**
/**
* YiiBase is a helper class serving common framework functionalities .
* YiiBase is the core helper class for the Yii framework .
*
*
* Do not use YiiBase directly. Instead, use its child class {@link Yii} where
* Do not use YiiBase directly. Instead, use its child class [[Yii]] where
* you can customize methods of YiiBase.
* you can customize methods of YiiBase.
*
*
* @author Qiang Xue < qiang.xue @ gmail . com >
* @author Qiang Xue < qiang.xue @ gmail . com >
* @version $Id: YiiBase.php 2895 2011-01-20 10:33:02Z mdomba $
* @since 2.0
* @package system
* @since 1.0
*/
*/
class YiiBase
class YiiBase
{
{
/**
/**
* @var array class map used by the Yii autoloading mechanism.
* @var array class map used by the Yii autoloading mechanism.
* The array keys are the class names and the array values are the corresponding class file paths.
* The array keys are the class names, and the array values are the corresponding class file paths.
* @since 1.1.5
* This property mainly affects how [[autoload]] works.
*/
public static $classMap = array();
/**
* @var array list of directories where Yii will search for new classes to be included.
* The first directory in the array will be searched first, and so on.
* This property mainly affects how [[autoload]] works.
*/
public static $classPath = array();
/**
* @var yii\base\Application the application instance
*/
*/
public static $classMap=array();
public static $app ;
private static $_aliases=array('system'=>YII_PATH,'zii'=>YII_ZII_PATH); // alias => path
private static $_aliases = array(
private static $_imports=array(); // alias => class name or directory
'@yii' => YII_PATH,
private static $_includePaths; // list of include paths
);
private static $_imports = array(); // alias => class name or directory
private static $_app;
private static $_app;
private static $_logger;
private static $_logger;
/**
/**
* @return string the version of Yii framework
* @return string the version of Yii framework
*/
*/
public static function getVersion()
public static function getVersion()
{
{
return '1.1.7 -dev';
return '2.0 -dev';
}
}
/**
/**
* Creates a Web application instance.
* Creates a Web application instance.
* @param mixed $config application configuration.
* @param mixed $config application configuration. This can be either an array representing
* If a string, it is treated as the path of the file that contains the configuration;
* the configuration to be applied to the newly created application instance, or a string
* If an array, it is the actual configuration information.
* referring to a PHP file returning the configuration array.
* Please make sure you specify the {@link CApplication::basePath basePath} property in the configuration,
* @return yii\web\Application the newly created application instance.
* which should point to the directory containing all application logic, template and data.
* If not, the directory will be defaulted to 'protected'.
*/
*/
public static function createWebApplication($config=null)
public static function createWebApplication($config = null)
{
{
return self::createApplication('CWebApplication', $config);
return new yii\web\Application( $config);
}
}
/**
/**
* Creates a console application instance.
* Creates a console application instance.
* @param mixed $config application configuration.
* @param mixed $config application configuration. This can be either an array representing
* If a string, it is treated as the path of the file that contains the configuration;
* the configuration to be applied to the newly created application instance, or a string
* If an array, it is the actual configuration information.
* referring to a PHP file returning the configuration array.
* Please make sure you specify the {@link CApplication::basePath basePath} property in the configuration,
* @return yii\console\Application the newly created application instance.
* which should point to the directory containing all application logic, template and data.
* If not, the directory will be defaulted to 'protected'.
*/
*/
public static function createConsoleApplication($config=null)
public static function createConsoleApplication($config = null)
{
{
return self::createApplication('CConsoleApplication',$config);
return new yii\console\Application($config);
}
/**
* Creates an application of the specified class.
* @param string $class the application class name
* @param mixed $config application configuration. This parameter will be passed as the parameter
* to the constructor of the application class.
* @return mixed the application instance
* @since 1.0.10
*/
public static function createApplication($class,$config=null)
{
return new $class($config);
}
/**
* Returns the application singleton, null if the singleton has not been created yet.
* @return CApplication the application singleton, null if the singleton has not been created yet.
*/
public static function app()
{
return self::$_app;
}
/**
* Stores the application instance in the class static member.
* This method helps implement a singleton pattern for CApplication.
* Repeated invocation of this method or the CApplication constructor
* will cause the throw of an exception.
* To retrieve the application instance, use {@link app()}.
* @param CApplication $app the application instance. If this is null, the existing
* application singleton will be removed.
* @throws CException if multiple application instances are registered.
*/
public static function setApplication($app)
{
if(self::$_app===null || $app===null)
self::$_app=$app;
else
throw new CException(Yii::t('yii','Yii application can only be created once.'));
}
}
/**
/**
* Returns the installation directory of the Yii framework.
* @return string the path of the framework
* @return string the path of the framework
*/
*/
public static function getFrameworkPath()
public static function getFrameworkPath()
@ -161,45 +134,45 @@ class YiiBase
*/
*/
public static function createComponent($config)
public static function createComponent($config)
{
{
if(is_string($config))
if (is_string($config))
{
{
$type=$config;
$type = $config;
$config=array();
$config = array();
}
}
else if(isset($config['class']))
elseif (isset($config['class']))
{
{
$type=$config['class'];
$type = $config['class'];
unset($config['class']);
unset($config['class']);
}
}
else
else
throw new CException(Yii::t('yii','Object configuration must be an array containing a "class" element.'));
throw new CException(Yii::t('yii', 'Object configuration must be an array containing a "class" element.'));
if(!class_exists($type,false))
if (!class_exists($type, false))
$type=Yii::import($type,true);
$type = Yii::import($type, true);
if(($n=func_num_args())>1)
if (($n = func_num_args()) > 1)
{
{
$args=func_get_args();
$args = func_get_args();
if($n===2)
if ($n === 2)
$object=new $type($args[1]);
$object = new $type($args[1]);
else if($n===3)
elseif ($n === 3)
$object=new $type($args[1],$args[2]);
$object = new $type($args[1], $args[2]);
else if($n===4)
elseif ($n === 4)
$object=new $type($args[1],$args[2],$args[3]);
$object = new $type($args[1], $args[2], $args[3]);
else
else
{
{
unset($args[0]);
unset($args[0]);
$class=new ReflectionClass($type);
$class = new ReflectionClass($type);
// Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+
// Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+
// $object=$class->newInstanceArgs($args);
// $object=$class->newInstanceArgs($args);
$object=call_user_func_array(array($class,'newInstance'),$args);
$object = call_user_func_array(array($class, 'newInstance'), $args);
}
}
}
}
else
else
$object=new $type;
$object = new $type;
foreach($config as $key=>$value)
foreach ($config as $key => $value)
$object->$key=$value;
$object->$key = $value;
return $object;
return $object;
}
}
@ -242,157 +215,190 @@ class YiiBase
* @return string the class name or the directory that this alias refers to
* @return string the class name or the directory that this alias refers to
* @throws CException if the alias is invalid
* @throws CException if the alias is invalid
*/
*/
public static function import($alias,$forceInclude=false)
public static function import($alias, $forceInclude = false)
{
{
if(isset(self::$_imports[$alias])) // previously imported
if (isset(self::$_imports[$alias])) // previously imported
return self::$_imports[$alias];
return self::$_imports[$alias];
if(class_exists($alias,false) || interface_exists($alias,false))
if (class_exists($alias, false) || interface_exists($alias, false))
return self::$_imports[$alias]=$alias;
return self::$_imports[$alias] = $alias;
if(($pos=strrpos($alias,'\\'))!==false) // a class name in PHP 5.3 namespace format
if (($pos = strrpos($alias, '\\')) !== false) // a class name in PHP 5.3 namespace format
{
{
$namespace=str_replace('\\','.',ltrim(substr($alias,0,$pos),'\\'));
$namespace = str_replace('\\', '.', ltrim(substr($alias, 0, $pos), '\\'));
if(($path=self::getPathOfAlias($namespace))!==false)
if (($path = self::getPathOfAlias($namespace)) !== false)
{
{
$classFile=$path.DIRECTORY_SEPARATOR.substr($alias,$pos+1).'.php';
$classFile = $path . DIRECTORY_SEPARATOR . substr($alias, $pos + 1) . '.php';
if($forceInclude)
if ($forceInclude)
{
{
if(is_file($classFile))
if (is_file($classFile))
require($classFile);
require($classFile);
else
else
throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file.',array('{alias}'=>$alias)));
throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file.', array('{alias}' => $alias)));
self::$_imports[$alias]=$alias;
self::$_imports[$alias] = $alias;
}
}
else
else
self::$classMap[$alias]=$classFile;
self::$classMap[$alias] = $classFile;
return $alias;
return $alias;
}
}
else
else
throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory.',
throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing directory.',
array('{alias}'=>$namespace)));
array('{alias}' => $namespace)));
}
}
if(($pos=strrpos($alias,'.'))===false) // a simple class name
if (($pos = strrpos($alias, '.')) === false) // a simple class name
{
{
if($forceInclude & & self::autoload($alias))
if ($forceInclude & & self::autoload($alias))
self::$_imports[$alias]=$alias;
self::$_imports[$alias] = $alias;
return $alias;
return $alias;
}
}
$className=(string)substr($alias,$pos+1);
$className = (string)substr($alias, $pos + 1);
$isClass=$className!=='*';
$isClass = $className !== '*';
if($isClass & & (class_exists($className,false) || interface_exists($className,false)))
if ($isClass & & (class_exists($className, false) || interface_exists($className, false)))
return self::$_imports[$alias]=$className;
return self::$_imports[$alias] = $className;
if(($path=self::getPathOfAlias($alias))!==false)
if (($path = self::getPathOfAlias($alias)) !== false)
{
{
if($isClass)
if ($isClass)
{
{
if($forceInclude)
if ($forceInclude)
{
{
if(is_file($path.'.php'))
if (is_file($path . '.php'))
require($path.'.php');
require($path . '.php');
else
else
throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file.',array('{alias}'=>$alias)));
throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file.', array('{alias}' => $alias)));
self::$_imports[$alias]=$className;
self::$_imports[$alias] = $className;
}
}
else
else
self::$classMap[$className]=$path.'.php';
self::$classMap[$className] = $path . '.php';
return $className;
return $className;
}
}
else // a directory
else // a directory
{
{
if(self::$_includePaths=== null)
if (self::$classPath === null)
{
{
self::$_includePaths=array_unique(explode(PATH_SEPARATOR, get_include_path()));
self::$classPath = array_unique(explode(PATH_SEPARATOR, get_include_path()));
if(($pos=array_search('.',self::$_includePaths,true))!== false)
if (($pos = array_search('.', self::$classPath, true)) !== false)
unset(self::$_includePaths [$pos]);
unset(self::$classPath [$pos]);
}
}
array_unshift(self::$_includePaths, $path);
array_unshift(self::$classPath, $path);
if(set_include_path('.'.PATH_SEPARATOR.implode(PATH_SEPARATOR,self::$_includePaths))=== false)
if (self::$useIncludePath & & set_include_path('.' . PATH_SEPARATOR . implode(PATH_SEPARATOR, self::$classPath)) === false)
throw new CException(Yii::t('yii','Unable to import "{alias}". Please check your server configuration to make sure you are allowed to change PHP include_path.',array('{alias}'=>$alias))) ;
self::$useIncludePath = false ;
return self::$_imports[$alias]=$path;
return self::$_imports[$alias] = $path;
}
}
}
}
else
else
throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
throw new CException(Yii::t('yii', 'Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
array('{alias}'=>$alias)));
array('{alias}' => $alias)));
}
}
/**
/**
* Translates an alias into a file path.
* Translates a path alias into an actual path.
* Note, this method does not ensure the existence of the resulting file path.
* The path alias can be either a root alias registered via [[setPathOfAlias]] or an
* It only checks if the root alias is valid or not.
* alias starting with a root alias (e.g. `@yii/base/Component.php`).
* @param string $alias alias (e.g. system.web.CController)
* In the latter case, the root alias will be replaced by the corresponding registered path
* @return mixed file path corresponding to the alias, false if the alias is invalid.
* and the remaining part will be appended to it.
* Note, this method does not ensure the existence of the resulting path.
* @param string $alias alias
* @return mixed path corresponding to the alias, false if the root alias is not previously registered.
* @see setPathOfAlias
*/
*/
public static function getPathOfAlias($alias)
public static function getPathOfAlias($alias)
{
{
if(isset(self::$_aliases[$alias]))
if (isset(self::$_aliases[$alias])) {
return self::$_aliases[$alias];
return self::$_aliases[$alias];
else if(($pos=strpos($alias,'.'))!==false)
}
{
elseif (($pos = strpos($alias, '/')) !== false) {
$rootAlias=substr($alias,0,$pos);
$rootAlias = substr($alias, 0, $pos);
if(isset(self::$_aliases[$rootAlias]))
if (isset(self::$_aliases[$rootAlias])) {
return self::$_aliases[$alias]=rtrim(self::$_aliases[$rootAlias].DIRECTORY_SEPARATOR.str_replace('.',DIRECTORY_SEPARATOR,substr($alias,$pos+1)),'*'.DIRECTORY_SEPARATOR);
return self::$_aliases[$alias] = self::$_aliases[$rootAlias] . substr($alias, $pos);
else if(self::$_app instanceof CWebApplication)
{
if(self::$_app->findModule($rootAlias)!==null)
return self::getPathOfAlias($alias);
}
}
}
}
return false;
return false;
}
}
/**
/**
* Create a path alias.
* Registers a path alias.
* Note, this method neither checks the existence of the path nor normalizes the path.
* A path alias is a short name representing a path (a file path, a URL, etc.)
* @param string $alias alias to the path
* A path alias must start with '@' (e.g. '@yii').
* Note that this method neither checks the existence of the path nor normalizes the path.
* @param string $alias alias to the path. The alias must start with '@'.
* @param string $path the path corresponding to the alias. If this is null, the corresponding
* @param string $path the path corresponding to the alias. If this is null, the corresponding
* path alias will be removed.
* path alias will be removed. The path can be a file path (e.g. `/tmp`) or a URL (e.g. `http://www.yiiframework.com`).
* @see getPathOfAlias
*/
*/
public static function setPathOfAlias($alias,$path)
public static function setPathOfAlias($alias, $path)
{
{
if(empty($path))
if ($path === null) {
unset(self::$_aliases[$alias]);
unset(self::$_aliases[$alias]);
else
}
self::$_aliases[$alias]=rtrim($path,'\\/');
else {
self::$_aliases[$alias] = rtrim($path, '\\/');
}
}
}
/**
/**
* Class autoload loader.
* Class autoload loader.
* This method is provided to be invoked within an __autoload() magic method.
* This method is invoked automatically when the execution encounters an unknown class.
* The method will attempt to include the class file as follows:
*
* 1. Search in [[classMap]];
* 2. If the class is namespaced (e.g. `yii\base\Component`), it will attempt
* to include the file associated with the corresponding path alias
* (e.g. `@yii/base/Component.php`);
* 3. If the class is named in PEAR style (e.g. `PHPUnit_Framework_TestCase`),
* it will attempt to include the file associated with the corresponding path alias
* (e.g. `@PHPUnit/Framework/TestCase.php`);
* 4. Search in [[classPath]];
* 5. Return false so that other autoloaders have chance to include the class file.
*
* @param string $className class name
* @param string $className class name
* @return boolean whether the class has been loaded successfully
* @return boolean whether the class has been loaded successfully
*/
*/
public static function autoload($className)
public static function autoload($className)
{
{
// use include so that the error PHP file may appear
if (isset(self::$classMap[$className])) {
if(isset(self::$_coreClasses[$className]))
include(YII_PATH.self::$_coreClasses[$className]);
else if(isset(self::$classMap[$className]))
include(self::$classMap[$className]);
include(self::$classMap[$className]);
else
return true;
{
}
if(strpos($className,'\\')===false)
include($className.'.php');
// namespaced class, e.g. yii\base\Component
else // class name with namespace in PHP 5.3
if (strpos($className, '\\') !== false) {
{
// convert namespace to path alias, e.g. yii\base\Component to @yii/base/Component
$namespace=str_replace('\\','.',ltrim($className,'\\'));
$alias = '@' . str_replace('\\', '/', $className);
if(($path=self::getPathOfAlias($namespace))!==false)
if (($path = self::getPathOfAlias($alias)) !== false) {
include($path.'.php');
include($path . '.php');
else
return true;
}
return false;
return false;
}
}
return class_exists($className,false) || interface_exists($className,false);
// PEAR-styled class, e.g. PHPUnit_Framework_TestCase
if (($pos = strpos($className, '_')) !== false) {
// convert class name to path alias, e.g. PHPUnit_Framework_TestCase to @PHPUnit/Framework/TestCase
$alias = '@' . str_replace('_', '/', $className);
if (($path = self::getPathOfAlias($alias)) !== false) {
include($path . '.php');
return true;
}
}
}
// search in include paths
foreach (self::$classPath as $path) {
$classFile = $path . DIRECTORY_SEPARATOR . $className . '.php';
if (is_file($classFile)) {
include($classFile);
return true;
return true;
}
}
}
return false;
}
/**
/**
* Writes a trace message.
* Writes a trace message.
@ -401,10 +407,11 @@ class YiiBase
* @param string $category category of the message
* @param string $category category of the message
* @see log
* @see log
*/
*/
public static function trace($msg,$category='application')
public static function trace($msg, $category = 'application')
{
{
if(YII_DEBUG)
if (YII_DEBUG) {
self::log($msg,CLogger::LEVEL_TRACE,$category);
self::log($msg, CLogger::LEVEL_TRACE, $category);
}
}
}
/**
/**
@ -416,25 +423,26 @@ class YiiBase
* @param string $level level of the message (e.g. 'trace', 'warning', 'error'). It is case-insensitive.
* @param string $level level of the message (e.g. 'trace', 'warning', 'error'). It is case-insensitive.
* @param string $category category of the message (e.g. 'system.web'). It is case-insensitive.
* @param string $category category of the message (e.g. 'system.web'). It is case-insensitive.
*/
*/
public static function log($msg,$level=CLogger::LEVEL_INFO,$category='application')
public static function log($msg, $level = CLogger::LEVEL_INFO, $category = 'application')
{
{
if(self::$_logger===null)
if (self::$_logger === null) {
self::$_logger=new CLogger;
self::$_logger = new CLogger;
if(YII_DEBUG & & YII_TRACE_LEVEL>0 & & $level!==CLogger::LEVEL_PROFILE)
}
if (YII_DEBUG & & YII_TRACE_LEVEL > 0 & & $level !== CLogger::LEVEL_PROFILE)
{
{
$traces=debug_backtrace();
$traces = debug_backtrace();
$count=0;
$count = 0;
foreach($traces as $trace)
foreach ($traces as $trace)
{
{
if(isset($trace['file'],$trace['line']) & & strpos($trace['file'],YII_PATH)!==0)
if (isset($trace['file'], $trace['line']) & & strpos($trace['file'], YII_PATH) !== 0)
{
{
$msg.="\nin ".$trace['file'].' ('.$trace['line'].')';
$msg .= "\nin " . $trace['file'] . ' (' . $trace['line'] . ')';
if(++$count>=YII_TRACE_LEVEL)
if (++$count >= YII_TRACE_LEVEL)
break;
break;
}
}
}
}
}
}
self::$_logger->log($msg,$level,$category);
self::$_logger->log($msg, $level, $category);
}
}
/**
/**
@ -458,9 +466,9 @@ class YiiBase
* @param string $category the category of this log message
* @param string $category the category of this log message
* @see endProfile
* @see endProfile
*/
*/
public static function beginProfile($token,$category='application')
public static function beginProfile($token, $category = 'application')
{
{
self::log('begin:'.$token,CLogger::LEVEL_PROFILE,$category);
self::log('begin:' . $token, CLogger::LEVEL_PROFILE, $category);
}
}
/**
/**
@ -470,9 +478,9 @@ class YiiBase
* @param string $category the category of this log message
* @param string $category the category of this log message
* @see beginProfile
* @see beginProfile
*/
*/
public static function endProfile($token,$category='application')
public static function endProfile($token, $category = 'application')
{
{
self::log('end:'.$token,CLogger::LEVEL_PROFILE,$category);
self::log('end:' . $token, CLogger::LEVEL_PROFILE, $category);
}
}
/**
/**
@ -480,10 +488,20 @@ class YiiBase
*/
*/
public static function getLogger()
public static function getLogger()
{
{
if(self::$_logger!==null)
if (self::$_logger !== null)
return self::$_logger;
return self::$_logger;
else
else
return self::$_logger=new CLogger;
return self::$_logger = new CLogger;
}
/**
* Sets the logger object.
* @param CLogger $logger the logger object.
* @since 1.1.8
*/
public static function setLogger($logger)
{
self::$_logger = $logger;
}
}
/**
/**
@ -519,273 +537,41 @@ class YiiBase
* @return string the translated message
* @return string the translated message
* @see CMessageSource
* @see CMessageSource
*/
*/
public static function t($category,$message,$params=array(),$source=null,$language=null)
public static function t($category, $message, $params = array(), $source = null, $language = null)
{
{
if(self::$_app!==null)
if (self::$_app !== null)
{
{
if($source===null)
if ($source === null)
$source=($category==='yii'||$category==='zii')?'coreMessages':'messages';
$source = ($category === 'yii' || $category === 'zii') ? 'coreMessages' : 'messages';
if(($source=self::$_app->getComponent($source))!==null)
if (($source = self::$_app->getComponent($source)) !== null)
$message=$source->translate($category,$message,$language);
$message = $source->translate($category, $message, $language);
}
}
if($params===array())
if ($params === array())
return $message;
return $message;
if(!is_array($params))
if (!is_array($params))
$params=array($params);
$params = array($params);
if(isset($params[0])) // number choice
if (isset($params[0])) // number choice
{
{
if(strpos($message,'|')!==false)
if (strpos($message, '|') !== false)
{
{
if(strpos($message,'#')===false)
if (strpos($message, '#') === false)
{
{
$chunks=explode('|',$message);
$chunks = explode('|', $message);
$expressions=self::$_app->getLocale($language)->getPluralRules();
$expressions = self::$_app->getLocale($language)->getPluralRules();
if($n=min(count($chunks),count($expressions)))
if ($n = min(count($chunks), count($expressions)))
{
{
for($i=0;$i< $n;$i++)
for ($i = 0;$i < $n;$i++)
$chunks[$i]=$expressions[$i].'#'.$chunks[$i];
$chunks[$i] = $expressions[$i] . '#' . $chunks[$i];
$message=implode('|',$chunks);
$message = implode('|', $chunks);
}
}
}
}
$message=CChoiceFormat::format($message,$params[0]);
$message = CChoiceFormat::format($message, $params[0]);
}
}
if(!isset($params['{n}']))
if (!isset($params['{n}']))
$params['{n}']=$params[0];
$params['{n}'] = $params[0];
unset($params[0]);
unset($params[0]);
}
}
return $params!==array() ? strtr($message,$params) : $message;
return $params !== array() ? strtr($message, $params) : $message;
}
}
/**
* Registers a new class autoloader.
* The new autoloader will be placed before {@link autoload} and after
* any other existing autoloaders.
* @param callback $callback a valid PHP callback (function name or array($className,$methodName)).
* @since 1.0.10
*/
public static function registerAutoloader($callback)
{
spl_autoload_unregister(array('YiiBase','autoload'));
spl_autoload_register($callback);
spl_autoload_register(array('YiiBase','autoload'));
}
/**
* @var array class map for core Yii classes.
* NOTE, DO NOT MODIFY THIS ARRAY MANUALLY. IF YOU CHANGE OR ADD SOME CORE CLASSES,
* PLEASE RUN 'build autoload' COMMAND TO UPDATE THIS ARRAY.
*/
private static $_coreClasses=array(
'CApplication' => '/base/CApplication.php',
'CApplicationComponent' => '/base/CApplicationComponent.php',
'CBehavior' => '/base/CBehavior.php',
'CComponent' => '/base/CComponent.php',
'CErrorEvent' => '/base/CErrorEvent.php',
'CErrorHandler' => '/base/CErrorHandler.php',
'CException' => '/base/CException.php',
'CExceptionEvent' => '/base/CExceptionEvent.php',
'CHttpException' => '/base/CHttpException.php',
'CModel' => '/base/CModel.php',
'CModelBehavior' => '/base/CModelBehavior.php',
'CModelEvent' => '/base/CModelEvent.php',
'CModule' => '/base/CModule.php',
'CSecurityManager' => '/base/CSecurityManager.php',
'CStatePersister' => '/base/CStatePersister.php',
'CApcCache' => '/caching/CApcCache.php',
'CCache' => '/caching/CCache.php',
'CDbCache' => '/caching/CDbCache.php',
'CDummyCache' => '/caching/CDummyCache.php',
'CEAcceleratorCache' => '/caching/CEAcceleratorCache.php',
'CFileCache' => '/caching/CFileCache.php',
'CMemCache' => '/caching/CMemCache.php',
'CWinCache' => '/caching/CWinCache.php',
'CXCache' => '/caching/CXCache.php',
'CZendDataCache' => '/caching/CZendDataCache.php',
'CCacheDependency' => '/caching/dependencies/CCacheDependency.php',
'CChainedCacheDependency' => '/caching/dependencies/CChainedCacheDependency.php',
'CDbCacheDependency' => '/caching/dependencies/CDbCacheDependency.php',
'CDirectoryCacheDependency' => '/caching/dependencies/CDirectoryCacheDependency.php',
'CExpressionDependency' => '/caching/dependencies/CExpressionDependency.php',
'CFileCacheDependency' => '/caching/dependencies/CFileCacheDependency.php',
'CGlobalStateCacheDependency' => '/caching/dependencies/CGlobalStateCacheDependency.php',
'CAttributeCollection' => '/collections/CAttributeCollection.php',
'CConfiguration' => '/collections/CConfiguration.php',
'CList' => '/collections/CList.php',
'CListIterator' => '/collections/CListIterator.php',
'CMap' => '/collections/CMap.php',
'CMapIterator' => '/collections/CMapIterator.php',
'CQueue' => '/collections/CQueue.php',
'CQueueIterator' => '/collections/CQueueIterator.php',
'CStack' => '/collections/CStack.php',
'CStackIterator' => '/collections/CStackIterator.php',
'CTypedList' => '/collections/CTypedList.php',
'CTypedMap' => '/collections/CTypedMap.php',
'CConsoleApplication' => '/console/CConsoleApplication.php',
'CConsoleCommand' => '/console/CConsoleCommand.php',
'CConsoleCommandRunner' => '/console/CConsoleCommandRunner.php',
'CHelpCommand' => '/console/CHelpCommand.php',
'CDbCommand' => '/db/CDbCommand.php',
'CDbConnection' => '/db/CDbConnection.php',
'CDbDataReader' => '/db/CDbDataReader.php',
'CDbException' => '/db/CDbException.php',
'CDbMigration' => '/db/CDbMigration.php',
'CDbTransaction' => '/db/CDbTransaction.php',
'CActiveFinder' => '/db/ar/CActiveFinder.php',
'CActiveRecord' => '/db/ar/CActiveRecord.php',
'CActiveRecordBehavior' => '/db/ar/CActiveRecordBehavior.php',
'CDbColumnSchema' => '/db/schema/CDbColumnSchema.php',
'CDbCommandBuilder' => '/db/schema/CDbCommandBuilder.php',
'CDbCriteria' => '/db/schema/CDbCriteria.php',
'CDbExpression' => '/db/schema/CDbExpression.php',
'CDbSchema' => '/db/schema/CDbSchema.php',
'CDbTableSchema' => '/db/schema/CDbTableSchema.php',
'CMssqlColumnSchema' => '/db/schema/mssql/CMssqlColumnSchema.php',
'CMssqlCommandBuilder' => '/db/schema/mssql/CMssqlCommandBuilder.php',
'CMssqlPdoAdapter' => '/db/schema/mssql/CMssqlPdoAdapter.php',
'CMssqlSchema' => '/db/schema/mssql/CMssqlSchema.php',
'CMssqlTableSchema' => '/db/schema/mssql/CMssqlTableSchema.php',
'CMysqlColumnSchema' => '/db/schema/mysql/CMysqlColumnSchema.php',
'CMysqlSchema' => '/db/schema/mysql/CMysqlSchema.php',
'CMysqlTableSchema' => '/db/schema/mysql/CMysqlTableSchema.php',
'COciColumnSchema' => '/db/schema/oci/COciColumnSchema.php',
'COciCommandBuilder' => '/db/schema/oci/COciCommandBuilder.php',
'COciSchema' => '/db/schema/oci/COciSchema.php',
'COciTableSchema' => '/db/schema/oci/COciTableSchema.php',
'CPgsqlColumnSchema' => '/db/schema/pgsql/CPgsqlColumnSchema.php',
'CPgsqlSchema' => '/db/schema/pgsql/CPgsqlSchema.php',
'CPgsqlTableSchema' => '/db/schema/pgsql/CPgsqlTableSchema.php',
'CSqliteColumnSchema' => '/db/schema/sqlite/CSqliteColumnSchema.php',
'CSqliteCommandBuilder' => '/db/schema/sqlite/CSqliteCommandBuilder.php',
'CSqliteSchema' => '/db/schema/sqlite/CSqliteSchema.php',
'CChoiceFormat' => '/i18n/CChoiceFormat.php',
'CDateFormatter' => '/i18n/CDateFormatter.php',
'CDbMessageSource' => '/i18n/CDbMessageSource.php',
'CGettextMessageSource' => '/i18n/CGettextMessageSource.php',
'CLocale' => '/i18n/CLocale.php',
'CMessageSource' => '/i18n/CMessageSource.php',
'CNumberFormatter' => '/i18n/CNumberFormatter.php',
'CPhpMessageSource' => '/i18n/CPhpMessageSource.php',
'CGettextFile' => '/i18n/gettext/CGettextFile.php',
'CGettextMoFile' => '/i18n/gettext/CGettextMoFile.php',
'CGettextPoFile' => '/i18n/gettext/CGettextPoFile.php',
'CDbLogRoute' => '/logging/CDbLogRoute.php',
'CEmailLogRoute' => '/logging/CEmailLogRoute.php',
'CFileLogRoute' => '/logging/CFileLogRoute.php',
'CLogFilter' => '/logging/CLogFilter.php',
'CLogRoute' => '/logging/CLogRoute.php',
'CLogRouter' => '/logging/CLogRouter.php',
'CLogger' => '/logging/CLogger.php',
'CProfileLogRoute' => '/logging/CProfileLogRoute.php',
'CWebLogRoute' => '/logging/CWebLogRoute.php',
'CDateTimeParser' => '/utils/CDateTimeParser.php',
'CFileHelper' => '/utils/CFileHelper.php',
'CFormatter' => '/utils/CFormatter.php',
'CMarkdownParser' => '/utils/CMarkdownParser.php',
'CPropertyValue' => '/utils/CPropertyValue.php',
'CTimestamp' => '/utils/CTimestamp.php',
'CVarDumper' => '/utils/CVarDumper.php',
'CBooleanValidator' => '/validators/CBooleanValidator.php',
'CCaptchaValidator' => '/validators/CCaptchaValidator.php',
'CCompareValidator' => '/validators/CCompareValidator.php',
'CDefaultValueValidator' => '/validators/CDefaultValueValidator.php',
'CEmailValidator' => '/validators/CEmailValidator.php',
'CExistValidator' => '/validators/CExistValidator.php',
'CFileValidator' => '/validators/CFileValidator.php',
'CFilterValidator' => '/validators/CFilterValidator.php',
'CInlineValidator' => '/validators/CInlineValidator.php',
'CNumberValidator' => '/validators/CNumberValidator.php',
'CRangeValidator' => '/validators/CRangeValidator.php',
'CRegularExpressionValidator' => '/validators/CRegularExpressionValidator.php',
'CRequiredValidator' => '/validators/CRequiredValidator.php',
'CSafeValidator' => '/validators/CSafeValidator.php',
'CStringValidator' => '/validators/CStringValidator.php',
'CTypeValidator' => '/validators/CTypeValidator.php',
'CUniqueValidator' => '/validators/CUniqueValidator.php',
'CUnsafeValidator' => '/validators/CUnsafeValidator.php',
'CUrlValidator' => '/validators/CUrlValidator.php',
'CValidator' => '/validators/CValidator.php',
'CActiveDataProvider' => '/web/CActiveDataProvider.php',
'CArrayDataProvider' => '/web/CArrayDataProvider.php',
'CAssetManager' => '/web/CAssetManager.php',
'CBaseController' => '/web/CBaseController.php',
'CCacheHttpSession' => '/web/CCacheHttpSession.php',
'CClientScript' => '/web/CClientScript.php',
'CController' => '/web/CController.php',
'CDataProvider' => '/web/CDataProvider.php',
'CDbHttpSession' => '/web/CDbHttpSession.php',
'CExtController' => '/web/CExtController.php',
'CFormModel' => '/web/CFormModel.php',
'CHttpCookie' => '/web/CHttpCookie.php',
'CHttpRequest' => '/web/CHttpRequest.php',
'CHttpSession' => '/web/CHttpSession.php',
'CHttpSessionIterator' => '/web/CHttpSessionIterator.php',
'COutputEvent' => '/web/COutputEvent.php',
'CPagination' => '/web/CPagination.php',
'CSort' => '/web/CSort.php',
'CSqlDataProvider' => '/web/CSqlDataProvider.php',
'CTheme' => '/web/CTheme.php',
'CThemeManager' => '/web/CThemeManager.php',
'CUploadedFile' => '/web/CUploadedFile.php',
'CUrlManager' => '/web/CUrlManager.php',
'CWebApplication' => '/web/CWebApplication.php',
'CWebModule' => '/web/CWebModule.php',
'CWidgetFactory' => '/web/CWidgetFactory.php',
'CAction' => '/web/actions/CAction.php',
'CInlineAction' => '/web/actions/CInlineAction.php',
'CViewAction' => '/web/actions/CViewAction.php',
'CAccessControlFilter' => '/web/auth/CAccessControlFilter.php',
'CAuthAssignment' => '/web/auth/CAuthAssignment.php',
'CAuthItem' => '/web/auth/CAuthItem.php',
'CAuthManager' => '/web/auth/CAuthManager.php',
'CBaseUserIdentity' => '/web/auth/CBaseUserIdentity.php',
'CDbAuthManager' => '/web/auth/CDbAuthManager.php',
'CPhpAuthManager' => '/web/auth/CPhpAuthManager.php',
'CUserIdentity' => '/web/auth/CUserIdentity.php',
'CWebUser' => '/web/auth/CWebUser.php',
'CFilter' => '/web/filters/CFilter.php',
'CFilterChain' => '/web/filters/CFilterChain.php',
'CInlineFilter' => '/web/filters/CInlineFilter.php',
'CForm' => '/web/form/CForm.php',
'CFormButtonElement' => '/web/form/CFormButtonElement.php',
'CFormElement' => '/web/form/CFormElement.php',
'CFormElementCollection' => '/web/form/CFormElementCollection.php',
'CFormInputElement' => '/web/form/CFormInputElement.php',
'CFormStringElement' => '/web/form/CFormStringElement.php',
'CGoogleApi' => '/web/helpers/CGoogleApi.php',
'CHtml' => '/web/helpers/CHtml.php',
'CJSON' => '/web/helpers/CJSON.php',
'CJavaScript' => '/web/helpers/CJavaScript.php',
'CPradoViewRenderer' => '/web/renderers/CPradoViewRenderer.php',
'CViewRenderer' => '/web/renderers/CViewRenderer.php',
'CWebService' => '/web/services/CWebService.php',
'CWebServiceAction' => '/web/services/CWebServiceAction.php',
'CWsdlGenerator' => '/web/services/CWsdlGenerator.php',
'CActiveForm' => '/web/widgets/CActiveForm.php',
'CAutoComplete' => '/web/widgets/CAutoComplete.php',
'CClipWidget' => '/web/widgets/CClipWidget.php',
'CContentDecorator' => '/web/widgets/CContentDecorator.php',
'CFilterWidget' => '/web/widgets/CFilterWidget.php',
'CFlexWidget' => '/web/widgets/CFlexWidget.php',
'CHtmlPurifier' => '/web/widgets/CHtmlPurifier.php',
'CInputWidget' => '/web/widgets/CInputWidget.php',
'CMarkdown' => '/web/widgets/CMarkdown.php',
'CMaskedTextField' => '/web/widgets/CMaskedTextField.php',
'CMultiFileUpload' => '/web/widgets/CMultiFileUpload.php',
'COutputCache' => '/web/widgets/COutputCache.php',
'COutputProcessor' => '/web/widgets/COutputProcessor.php',
'CStarRating' => '/web/widgets/CStarRating.php',
'CTabView' => '/web/widgets/CTabView.php',
'CTextHighlighter' => '/web/widgets/CTextHighlighter.php',
'CTreeView' => '/web/widgets/CTreeView.php',
'CWidget' => '/web/widgets/CWidget.php',
'CCaptcha' => '/web/widgets/captcha/CCaptcha.php',
'CCaptchaAction' => '/web/widgets/captcha/CCaptchaAction.php',
'CBasePager' => '/web/widgets/pagers/CBasePager.php',
'CLinkPager' => '/web/widgets/pagers/CLinkPager.php',
'CListPager' => '/web/widgets/pagers/CListPager.php',
);
}
}
spl_autoload_register(array('YiiBase','autoload'));
require(YII_PATH.'/base/interfaces.php');