"Fossies" - the Fresh Open Source Software Archive

Member "yii-1.1.22.bf1d26/framework/YiiBase.php" (16 Jan 2020, 36225 Bytes) of package /linux/www/yii-1.1.22.bf1d26.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "YiiBase.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.1.21.733ac5_vs_1.1.22.bf1d26.

    1 <?php
    2 /**
    3  * YiiBase class file.
    4  *
    5  * @author Qiang Xue <qiang.xue@gmail.com>
    6  * @link http://www.yiiframework.com/
    7  * @copyright 2008-2013 Yii Software LLC
    8  * @license http://www.yiiframework.com/license/
    9  * @package system
   10  * @since 1.0
   11  */
   12 
   13 /**
   14  * Gets the application start timestamp.
   15  */
   16 defined('YII_BEGIN_TIME') or define('YII_BEGIN_TIME',microtime(true));
   17 /**
   18  * This constant defines whether the application should be in debug mode or not. Defaults to false.
   19  */
   20 defined('YII_DEBUG') or define('YII_DEBUG',false);
   21 /**
   22  * This constant defines how much call stack information (file name and line number) should be logged by Yii::trace().
   23  * Defaults to 0, meaning no backtrace information. If it is greater than 0,
   24  * at most that number of call stacks will be logged. Note, only user application call stacks are considered.
   25  */
   26 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);
   27 /**
   28  * This constant defines whether exception handling should be enabled. Defaults to true.
   29  */
   30 defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER',true);
   31 /**
   32  * This constant defines whether error handling should be enabled. Defaults to true.
   33  */
   34 defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER',true);
   35 /**
   36  * Defines the Yii framework installation path.
   37  */
   38 defined('YII_PATH') or define('YII_PATH',dirname(__FILE__));
   39 /**
   40  * Defines the Zii library installation path.
   41  */
   42 defined('YII_ZII_PATH') or define('YII_ZII_PATH',YII_PATH.DIRECTORY_SEPARATOR.'zii');
   43 
   44 /**
   45  * YiiBase is a helper class serving common framework functionalities.
   46  *
   47  * Do not use YiiBase directly. Instead, use its child class {@link Yii} where
   48  * you can customize methods of YiiBase.
   49  *
   50  * @author Qiang Xue <qiang.xue@gmail.com>
   51  * @package system
   52  * @since 1.0
   53  */
   54 class YiiBase
   55 {
   56     /**
   57      * @var array filters for autoloading mechanism.
   58      * It should be callable. For callable function autoloader pass className.
   59      * If filter function returns true Yii autoloader will be skipped.
   60      * @since 1.1.20
   61      */
   62     public static $autoloaderFilters=array();
   63     /**
   64      * @var array class map used by the Yii autoloading mechanism.
   65      * The array keys are the class names and the array values are the corresponding class file paths.
   66      * @since 1.1.5
   67      */
   68     public static $classMap=array();
   69     /**
   70      * @var boolean whether to rely on PHP include path to autoload class files. Defaults to true.
   71      * You may set this to be false if your hosting environment doesn't allow changing the PHP
   72      * include path, or if you want to append additional autoloaders to the default Yii autoloader.
   73      * @since 1.1.8
   74      */
   75     public static $enableIncludePath=true;
   76 
   77     private static $_aliases=array('system'=>YII_PATH,'zii'=>YII_ZII_PATH); // alias => path
   78     private static $_imports=array();                   // alias => class name or directory
   79     private static $_includePaths;                      // list of include paths
   80     private static $_app;
   81     private static $_logger;
   82 
   83 
   84 
   85     /**
   86      * @return string the version of Yii framework
   87      */
   88     public static function getVersion()
   89     {
   90         return '1.1.22';
   91     }
   92 
   93     /**
   94      * Creates a Web application instance.
   95      * @param mixed $config application configuration.
   96      * If a string, it is treated as the path of the file that contains the configuration;
   97      * If an array, it is the actual configuration information.
   98      * Please make sure you specify the {@link CApplication::basePath basePath} property in the configuration,
   99      * which should point to the directory containing all application logic, template and data.
  100      * If not, the directory will be defaulted to 'protected'.
  101      * @return CWebApplication
  102      */
  103     public static function createWebApplication($config=null)
  104     {
  105         return self::createApplication('CWebApplication',$config);
  106     }
  107 
  108     /**
  109      * Creates a console application instance.
  110      * @param mixed $config application configuration.
  111      * If a string, it is treated as the path of the file that contains the configuration;
  112      * If an array, it is the actual configuration information.
  113      * Please make sure you specify the {@link CApplication::basePath basePath} property in the configuration,
  114      * which should point to the directory containing all application logic, template and data.
  115      * If not, the directory will be defaulted to 'protected'.
  116      * @return CConsoleApplication
  117      */
  118     public static function createConsoleApplication($config=null)
  119     {
  120         return self::createApplication('CConsoleApplication',$config);
  121     }
  122 
  123     /**
  124      * Creates an application of the specified class.
  125      * @param string $class the application class name
  126      * @param mixed $config application configuration. This parameter will be passed as the parameter
  127      * to the constructor of the application class.
  128      * @return mixed the application instance
  129      */
  130     public static function createApplication($class,$config=null)
  131     {
  132         return new $class($config);
  133     }
  134 
  135     /**
  136      * Returns the application singleton or null if the singleton has not been created yet.
  137      * @return CApplication the application singleton, null if the singleton has not been created yet.
  138      */
  139     public static function app()
  140     {
  141         return self::$_app;
  142     }
  143 
  144     /**
  145      * Stores the application instance in the class static member.
  146      * This method helps implement a singleton pattern for CApplication.
  147      * Repeated invocation of this method or the CApplication constructor
  148      * will cause the throw of an exception.
  149      * To retrieve the application instance, use {@link app()}.
  150      * @param CApplication $app the application instance. If this is null, the existing
  151      * application singleton will be removed.
  152      * @throws CException if multiple application instances are registered.
  153      */
  154     public static function setApplication($app)
  155     {
  156         if(self::$_app===null || $app===null)
  157             self::$_app=$app;
  158         else
  159             throw new CException(Yii::t('yii','Yii application can only be created once.'));
  160     }
  161 
  162     /**
  163      * @return string the path of the framework
  164      */
  165     public static function getFrameworkPath()
  166     {
  167         return YII_PATH;
  168     }
  169 
  170     /**
  171      * Creates an object and initializes it based on the given configuration.
  172      *
  173      * The specified configuration can be either a string or an array.
  174      * If the former, the string is treated as the object type which can
  175      * be either the class name or {@link YiiBase::getPathOfAlias class path alias}.
  176      * If the latter, the 'class' element is treated as the object type,
  177      * and the rest of the name-value pairs in the array are used to initialize
  178      * the corresponding object properties.
  179      *
  180      * Any additional parameters passed to this method will be
  181      * passed to the constructor of the object being created.
  182      *
  183      * @param mixed $config the configuration. It can be either a string or an array.
  184      * @return mixed the created object
  185      * @throws CException if the configuration does not have a 'class' element.
  186      */
  187     public static function createComponent($config)
  188     {
  189         $args = func_get_args();
  190         if(is_string($config))
  191         {
  192             $type=$config;
  193             $config=array();
  194         }
  195         elseif(isset($config['class']))
  196         {
  197             $type=$config['class'];
  198             unset($config['class']);
  199         }
  200         else
  201             throw new CException(Yii::t('yii','Object configuration must be an array containing a "class" element.'));
  202 
  203         if(!class_exists($type,false))
  204             $type=Yii::import($type,true);
  205 
  206         if(($n=func_num_args())>1)
  207         {
  208             if($n===2)
  209                 $object=new $type($args[1]);
  210             elseif($n===3)
  211                 $object=new $type($args[1],$args[2]);
  212             elseif($n===4)
  213                 $object=new $type($args[1],$args[2],$args[3]);
  214             else
  215             {
  216                 unset($args[0]);
  217                 $class=new ReflectionClass($type);
  218                 // Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+
  219                 // $object=$class->newInstanceArgs($args);
  220                 $object=call_user_func_array(array($class,'newInstance'),$args);
  221             }
  222         }
  223         else
  224             $object=new $type;
  225 
  226         foreach($config as $key=>$value)
  227             $object->$key=$value;
  228 
  229         return $object;
  230     }
  231 
  232     /**
  233      * Imports a class or a directory.
  234      *
  235      * Importing a class is like including the corresponding class file.
  236      * The main difference is that importing a class is much lighter because it only
  237      * includes the class file when the class is referenced the first time.
  238      *
  239      * Importing a directory is equivalent to adding a directory into the PHP include path.
  240      * If multiple directories are imported, the directories imported later will take
  241      * precedence in class file searching (i.e., they are added to the front of the PHP include path).
  242      *
  243      * Path aliases are used to import a class or directory. For example,
  244      * <ul>
  245      *   <li><code>application.components.GoogleMap</code>: import the <code>GoogleMap</code> class.</li>
  246      *   <li><code>application.components.*</code>: import the <code>components</code> directory.</li>
  247      * </ul>
  248      *
  249      * The same path alias can be imported multiple times, but only the first time is effective.
  250      * Importing a directory does not import any of its subdirectories.
  251      *
  252      * Starting from version 1.1.5, this method can also be used to import a class in namespace format
  253      * (available for PHP 5.3 or above only). It is similar to importing a class in path alias format,
  254      * except that the dot separator is replaced by the backslash separator. For example, importing
  255      * <code>application\components\GoogleMap</code> is similar to importing <code>application.components.GoogleMap</code>.
  256      * The difference is that the former class is using qualified name, while the latter unqualified.
  257      *
  258      * Note, importing a class in namespace format requires that the namespace corresponds to
  259      * a valid path alias once backslash characters are replaced with dot characters.
  260      * For example, the namespace <code>application\components</code> must correspond to a valid
  261      * path alias <code>application.components</code>.
  262      *
  263      * @param string $alias path alias to be imported
  264      * @param boolean $forceInclude whether to include the class file immediately. If false, the class file
  265      * will be included only when the class is being used. This parameter is used only when
  266      * the path alias refers to a class.
  267      * @return string the class name or the directory that this alias refers to
  268      * @throws CException if the alias is invalid
  269      */
  270     public static function import($alias,$forceInclude=false)
  271     {
  272         if(isset(self::$_imports[$alias]))  // previously imported
  273             return self::$_imports[$alias];
  274 
  275         if(class_exists($alias,false) || interface_exists($alias,false))
  276             return self::$_imports[$alias]=$alias;
  277 
  278         if(($pos=strrpos($alias,'\\'))!==false) // a class name in PHP 5.3 namespace format
  279         {
  280             $namespace=str_replace('\\','.',ltrim(substr($alias,0,$pos),'\\'));
  281             if(($path=self::getPathOfAlias($namespace))!==false)
  282             {
  283                 $classFile=$path.DIRECTORY_SEPARATOR.substr($alias,$pos+1).'.php';
  284                 if($forceInclude)
  285                 {
  286                     if(is_file($classFile))
  287                         require($classFile);
  288                     else
  289                         throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.',array('{alias}'=>$alias)));
  290                     self::$_imports[$alias]=$alias;
  291                 }
  292                 else
  293                     self::$classMap[$alias]=$classFile;
  294                 return $alias;
  295             }
  296             else
  297             {
  298                 // try to autoload the class with an autoloader
  299                 if (class_exists($alias,true))
  300                     return self::$_imports[$alias]=$alias;
  301                 else
  302                     throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
  303                         array('{alias}'=>$namespace)));
  304             }
  305         }
  306 
  307         if(($pos=strrpos($alias,'.'))===false)  // a simple class name
  308         {
  309             // try to autoload the class with an autoloader if $forceInclude is true
  310             if($forceInclude && (Yii::autoload($alias,true) || class_exists($alias,true)))
  311                 self::$_imports[$alias]=$alias;
  312             return $alias;
  313         }
  314 
  315         $className=(string)substr($alias,$pos+1);
  316         $isClass=$className!=='*';
  317 
  318         if($isClass && (class_exists($className,false) || interface_exists($className,false)))
  319             return self::$_imports[$alias]=$className;
  320 
  321         if(($path=self::getPathOfAlias($alias))!==false)
  322         {
  323             if($isClass)
  324             {
  325                 if($forceInclude)
  326                 {
  327                     if(is_file($path.'.php'))
  328                         require($path.'.php');
  329                     else
  330                         throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.',array('{alias}'=>$alias)));
  331                     self::$_imports[$alias]=$className;
  332                 }
  333                 else
  334                     self::$classMap[$className]=$path.'.php';
  335                 return $className;
  336             }
  337             else  // a directory
  338             {
  339                 if(self::$_includePaths===null)
  340                 {
  341                     self::$_includePaths=array_unique(explode(PATH_SEPARATOR,get_include_path()));
  342                     if(($pos=array_search('.',self::$_includePaths,true))!==false)
  343                         unset(self::$_includePaths[$pos]);
  344                 }
  345 
  346                 array_unshift(self::$_includePaths,$path);
  347 
  348                 if(self::$enableIncludePath && set_include_path('.'.PATH_SEPARATOR.implode(PATH_SEPARATOR,self::$_includePaths))===false)
  349                     self::$enableIncludePath=false;
  350 
  351                 return self::$_imports[$alias]=$path;
  352             }
  353         }
  354         else
  355             throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
  356                 array('{alias}'=>$alias)));
  357     }
  358 
  359     /**
  360      * Translates an alias into a file path.
  361      * Note, this method does not ensure the existence of the resulting file path.
  362      * It only checks if the root alias is valid or not.
  363      * @param string $alias alias (e.g. system.web.CController)
  364      * @return mixed file path corresponding to the alias, false if the alias is invalid.
  365      */
  366     public static function getPathOfAlias($alias)
  367     {
  368         if(isset(self::$_aliases[$alias]))
  369             return self::$_aliases[$alias];
  370         elseif(($pos=strpos($alias,'.'))!==false)
  371         {
  372             $rootAlias=substr($alias,0,$pos);
  373             if(isset(self::$_aliases[$rootAlias]))
  374                 return self::$_aliases[$alias]=rtrim(self::$_aliases[$rootAlias].DIRECTORY_SEPARATOR.str_replace('.',DIRECTORY_SEPARATOR,substr($alias,$pos+1)),'*'.DIRECTORY_SEPARATOR);
  375             elseif(self::$_app instanceof CWebApplication)
  376             {
  377                 if(self::$_app->findModule($rootAlias)!==null)
  378                     return self::getPathOfAlias($alias);
  379             }
  380         }
  381         return false;
  382     }
  383 
  384     /**
  385      * Create a path alias.
  386      * Note, this method neither checks the existence of the path nor normalizes the path.
  387      * @param string $alias alias to the path
  388      * @param string $path the path corresponding to the alias. If this is null, the corresponding
  389      * path alias will be removed.
  390      */
  391     public static function setPathOfAlias($alias,$path)
  392     {
  393         if(empty($path))
  394             unset(self::$_aliases[$alias]);
  395         else
  396             self::$_aliases[$alias]=rtrim($path,'\\/');
  397     }
  398 
  399     /**
  400      * Class autoload loader.
  401      * This method is provided to be invoked within an __autoload() magic method.
  402      * @param string $className class name
  403      * @param bool $classMapOnly whether to load classes via classmap only
  404      * @return boolean whether the class has been loaded successfully
  405      * @throws CException When class name does not match class file in debug mode.
  406      */
  407     public static function autoload($className,$classMapOnly=false)
  408     {
  409         foreach (self::$autoloaderFilters as $filter)
  410         {
  411             if (is_array($filter)
  412                 && isset($filter[0]) && isset($filter[1])
  413                 && is_string($filter[0]) && is_string($filter[1])
  414                 && true === call_user_func(array($filter[0], $filter[1]), $className)
  415             )
  416             {
  417                 return true;
  418             }
  419             elseif (is_string($filter)
  420                 && true === call_user_func($filter, $className)
  421             )
  422             {
  423                 return true;
  424             }
  425             elseif (is_callable($filter)
  426                 && true === $filter($className)
  427             )
  428             {
  429                 return true;
  430             }
  431         }
  432 
  433         // use include so that the error PHP file may appear
  434         if(isset(self::$classMap[$className]))
  435             include(self::$classMap[$className]);
  436         elseif(isset(self::$_coreClasses[$className]))
  437             include(YII_PATH.self::$_coreClasses[$className]);
  438         elseif($classMapOnly)
  439             return false;
  440         else
  441         {
  442             // include class file relying on include_path
  443             if(strpos($className,'\\')===false)  // class without namespace
  444             {
  445                 if(self::$enableIncludePath===false)
  446                 {
  447                     foreach(self::$_includePaths as $path)
  448                     {
  449                         $classFile=$path.DIRECTORY_SEPARATOR.$className.'.php';
  450                         if(is_file($classFile))
  451                         {
  452                             include($classFile);
  453                             if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php')
  454                                 throw new CException(Yii::t('yii','Class name "{class}" does not match class file "{file}".', array(
  455                                     '{class}'=>$className,
  456                                     '{file}'=>$classFile,
  457                                 )));
  458                             break;
  459                         }
  460                     }
  461                 }
  462                 else
  463                     include($className.'.php');
  464             }
  465             else  // class name with namespace in PHP 5.3
  466             {
  467                 $namespace=str_replace('\\','.',ltrim($className,'\\'));
  468                 if(($path=self::getPathOfAlias($namespace))!==false && is_file($path.'.php'))
  469                     include($path.'.php');
  470                 else
  471                     return false;
  472             }
  473             return class_exists($className,false) || interface_exists($className,false);
  474         }
  475         return true;
  476     }
  477 
  478     /**
  479      * Writes a trace message.
  480      * This method will only log a message when the application is in debug mode.
  481      * @param string $msg message to be logged
  482      * @param string $category category of the message
  483      * @see log
  484      */
  485     public static function trace($msg,$category='application')
  486     {
  487         if(YII_DEBUG)
  488             self::log($msg,CLogger::LEVEL_TRACE,$category);
  489     }
  490 
  491     /**
  492      * Logs a message.
  493      * Messages logged by this method may be retrieved via {@link CLogger::getLogs}
  494      * and may be recorded in different media, such as file, email, database, using
  495      * {@link CLogRouter}.
  496      * @param string $msg message to be logged
  497      * @param string $level level of the message (e.g. 'trace', 'warning', 'error'). It is case-insensitive.
  498      * @param string $category category of the message (e.g. 'system.web'). It is case-insensitive.
  499      */
  500     public static function log($msg,$level=CLogger::LEVEL_INFO,$category='application')
  501     {
  502         if(self::$_logger===null)
  503             self::$_logger=new CLogger;
  504         if(YII_DEBUG && YII_TRACE_LEVEL>0 && $level!==CLogger::LEVEL_PROFILE)
  505         {
  506             $traces=debug_backtrace();
  507             $count=0;
  508             foreach($traces as $trace)
  509             {
  510                 if(isset($trace['file'],$trace['line']) && strpos($trace['file'],YII_PATH)!==0)
  511                 {
  512                     $msg.="\nin ".$trace['file'].' ('.$trace['line'].')';
  513                     if(++$count>=YII_TRACE_LEVEL)
  514                         break;
  515                 }
  516             }
  517         }
  518         self::$_logger->log($msg,$level,$category);
  519     }
  520 
  521     /**
  522      * Marks the beginning of a code block for profiling.
  523      * This has to be matched with a call to {@link endProfile()} with the same token.
  524      * The begin- and end- calls must also be properly nested, e.g.,
  525      * <pre>
  526      * Yii::beginProfile('block1');
  527      * Yii::beginProfile('block2');
  528      * Yii::endProfile('block2');
  529      * Yii::endProfile('block1');
  530      * </pre>
  531      * The following sequence is not valid:
  532      * <pre>
  533      * Yii::beginProfile('block1');
  534      * Yii::beginProfile('block2');
  535      * Yii::endProfile('block1');
  536      * Yii::endProfile('block2');
  537      * </pre>
  538      * @param string $token token for the code block
  539      * @param string $category the category of this log message
  540      * @see endProfile
  541      */
  542     public static function beginProfile($token,$category='application')
  543     {
  544         self::log('begin:'.$token,CLogger::LEVEL_PROFILE,$category);
  545     }
  546 
  547     /**
  548      * Marks the end of a code block for profiling.
  549      * This has to be matched with a previous call to {@link beginProfile()} with the same token.
  550      * @param string $token token for the code block
  551      * @param string $category the category of this log message
  552      * @see beginProfile
  553      */
  554     public static function endProfile($token,$category='application')
  555     {
  556         self::log('end:'.$token,CLogger::LEVEL_PROFILE,$category);
  557     }
  558 
  559     /**
  560      * @return CLogger message logger
  561      */
  562     public static function getLogger()
  563     {
  564         if(self::$_logger!==null)
  565             return self::$_logger;
  566         else
  567             return self::$_logger=new CLogger;
  568     }
  569 
  570     /**
  571      * Sets the logger object.
  572      * @param CLogger $logger the logger object.
  573      * @since 1.1.8
  574      */
  575     public static function setLogger($logger)
  576     {
  577         self::$_logger=$logger;
  578     }
  579 
  580     /**
  581      * Returns a string that can be displayed on your Web page showing Powered-by-Yii information
  582      * @return string a string that can be displayed on your Web page showing Powered-by-Yii information
  583      */
  584     public static function powered()
  585     {
  586         return Yii::t('yii','Powered by {yii}.', array('{yii}'=>'<a href="http://www.yiiframework.com/" rel="external">Yii Framework</a>'));
  587     }
  588 
  589     /**
  590      * Translates a message to the specified language.
  591      * This method supports choice format (see {@link CChoiceFormat}),
  592      * i.e., the message returned will be chosen from a few candidates according to the given
  593      * number value. This feature is mainly used to solve plural format issue in case
  594      * a message has different plural forms in some languages.
  595      * @param string $category message category. Please use only word letters. Note, category 'yii' is
  596      * reserved for Yii framework core code use. See {@link CPhpMessageSource} for
  597      * more interpretation about message category.
  598      * @param string $message the original message
  599      * @param array $params parameters to be applied to the message using <code>strtr</code>.
  600      * The first parameter can be a number without key.
  601      * And in this case, the method will call {@link CChoiceFormat::format} to choose
  602      * an appropriate message translation.
  603      * Starting from version 1.1.6 you can pass parameter for {@link CChoiceFormat::format}
  604      * or plural forms format without wrapping it with array.
  605      * This parameter is then available as <code>{n}</code> in the message translation string.
  606      * @param string $source which message source application component to use.
  607      * Defaults to null, meaning using 'coreMessages' for messages belonging to
  608      * the 'yii' category and using 'messages' for the rest messages.
  609      * @param string $language the target language. If null (default), the {@link CApplication::getLanguage application language} will be used.
  610      * @return string the translated message
  611      * @see CMessageSource
  612      */
  613     public static function t($category,$message,$params=array(),$source=null,$language=null)
  614     {
  615         if(self::$_app!==null)
  616         {
  617             if($source===null)
  618                 $source=($category==='yii'||$category==='zii')?'coreMessages':'messages';
  619             if(($source=self::$_app->getComponent($source))!==null)
  620                 $message=$source->translate($category,$message,$language);
  621         }
  622         if($params===array())
  623             return $message;
  624         if(!is_array($params))
  625             $params=array($params);
  626         if(isset($params[0])) // number choice
  627         {
  628             if(strpos($message,'|')!==false)
  629             {
  630                 if(strpos($message,'#')===false)
  631                 {
  632                     $chunks=explode('|',$message);
  633                     $expressions=self::$_app->getLocale($language)->getPluralRules();
  634                     if($n=min(count($chunks),count($expressions)))
  635                     {
  636                         for($i=0;$i<$n;$i++)
  637                             $chunks[$i]=$expressions[$i].'#'.$chunks[$i];
  638 
  639                         $message=implode('|',$chunks);
  640                     }
  641                 }
  642                 $message=CChoiceFormat::format($message,$params[0]);
  643             }
  644             if(!isset($params['{n}']))
  645                 $params['{n}']=$params[0];
  646             unset($params[0]);
  647         }
  648         return $params!==array() ? strtr($message,$params) : $message;
  649     }
  650 
  651     /**
  652      * Registers a new class autoloader.
  653      * The new autoloader will be placed before {@link autoload} and after
  654      * any other existing autoloaders.
  655      * @param callback $callback a valid PHP callback (function name or array($className,$methodName)).
  656      * @param boolean $append whether to append the new autoloader after the default Yii autoloader.
  657      * Be careful using this option as it will disable {@link enableIncludePath autoloading via include path}
  658      * when set to true. After this the Yii autoloader can not rely on loading classes via simple include anymore
  659      * and you have to {@link import} all classes explicitly.
  660      */
  661     public static function registerAutoloader($callback, $append=false)
  662     {
  663         if($append)
  664         {
  665             self::$enableIncludePath=false;
  666             spl_autoload_register($callback);
  667         }
  668         else
  669         {
  670             spl_autoload_unregister(array('YiiBase','autoload'));
  671             spl_autoload_register($callback);
  672             spl_autoload_register(array('YiiBase','autoload'));
  673         }
  674     }
  675 
  676     /**
  677      * @var array class map for core Yii classes.
  678      * NOTE, DO NOT MODIFY THIS ARRAY MANUALLY. IF YOU CHANGE OR ADD SOME CORE CLASSES,
  679      * PLEASE RUN 'build autoload' COMMAND TO UPDATE THIS ARRAY.
  680      */
  681     private static $_coreClasses=array(
  682         'CApplication' => '/base/CApplication.php',
  683         'CApplicationComponent' => '/base/CApplicationComponent.php',
  684         'CBehavior' => '/base/CBehavior.php',
  685         'CComponent' => '/base/CComponent.php',
  686         'CDbStatePersister' => '/base/CDbStatePersister.php',
  687         'CErrorEvent' => '/base/CErrorEvent.php',
  688         'CErrorHandler' => '/base/CErrorHandler.php',
  689         'CException' => '/base/CException.php',
  690         'CExceptionEvent' => '/base/CExceptionEvent.php',
  691         'CHttpException' => '/base/CHttpException.php',
  692         'CModel' => '/base/CModel.php',
  693         'CModelBehavior' => '/base/CModelBehavior.php',
  694         'CModelEvent' => '/base/CModelEvent.php',
  695         'CModule' => '/base/CModule.php',
  696         'CSecurityManager' => '/base/CSecurityManager.php',
  697         'CStatePersister' => '/base/CStatePersister.php',
  698         'CApcCache' => '/caching/CApcCache.php',
  699         'CCache' => '/caching/CCache.php',
  700         'CDbCache' => '/caching/CDbCache.php',
  701         'CDummyCache' => '/caching/CDummyCache.php',
  702         'CEAcceleratorCache' => '/caching/CEAcceleratorCache.php',
  703         'CFileCache' => '/caching/CFileCache.php',
  704         'CMemCache' => '/caching/CMemCache.php',
  705         'CRedisCache' => '/caching/CRedisCache.php',
  706         'CWinCache' => '/caching/CWinCache.php',
  707         'CXCache' => '/caching/CXCache.php',
  708         'CZendDataCache' => '/caching/CZendDataCache.php',
  709         'CCacheDependency' => '/caching/dependencies/CCacheDependency.php',
  710         'CChainedCacheDependency' => '/caching/dependencies/CChainedCacheDependency.php',
  711         'CDbCacheDependency' => '/caching/dependencies/CDbCacheDependency.php',
  712         'CDirectoryCacheDependency' => '/caching/dependencies/CDirectoryCacheDependency.php',
  713         'CExpressionDependency' => '/caching/dependencies/CExpressionDependency.php',
  714         'CFileCacheDependency' => '/caching/dependencies/CFileCacheDependency.php',
  715         'CGlobalStateCacheDependency' => '/caching/dependencies/CGlobalStateCacheDependency.php',
  716         'CAttributeCollection' => '/collections/CAttributeCollection.php',
  717         'CConfiguration' => '/collections/CConfiguration.php',
  718         'CList' => '/collections/CList.php',
  719         'CListIterator' => '/collections/CListIterator.php',
  720         'CMap' => '/collections/CMap.php',
  721         'CMapIterator' => '/collections/CMapIterator.php',
  722         'CQueue' => '/collections/CQueue.php',
  723         'CQueueIterator' => '/collections/CQueueIterator.php',
  724         'CStack' => '/collections/CStack.php',
  725         'CStackIterator' => '/collections/CStackIterator.php',
  726         'CTypedList' => '/collections/CTypedList.php',
  727         'CTypedMap' => '/collections/CTypedMap.php',
  728         'CConsoleApplication' => '/console/CConsoleApplication.php',
  729         'CConsoleCommand' => '/console/CConsoleCommand.php',
  730         'CConsoleCommandBehavior' => '/console/CConsoleCommandBehavior.php',
  731         'CConsoleCommandEvent' => '/console/CConsoleCommandEvent.php',
  732         'CConsoleCommandRunner' => '/console/CConsoleCommandRunner.php',
  733         'CHelpCommand' => '/console/CHelpCommand.php',
  734         'CDbCommand' => '/db/CDbCommand.php',
  735         'CDbConnection' => '/db/CDbConnection.php',
  736         'CDbDataReader' => '/db/CDbDataReader.php',
  737         'CDbException' => '/db/CDbException.php',
  738         'CDbMigration' => '/db/CDbMigration.php',
  739         'CDbTransaction' => '/db/CDbTransaction.php',
  740         'CActiveFinder' => '/db/ar/CActiveFinder.php',
  741         'CActiveRecord' => '/db/ar/CActiveRecord.php',
  742         'CActiveRecordBehavior' => '/db/ar/CActiveRecordBehavior.php',
  743         'CDbColumnSchema' => '/db/schema/CDbColumnSchema.php',
  744         'CDbCommandBuilder' => '/db/schema/CDbCommandBuilder.php',
  745         'CDbCriteria' => '/db/schema/CDbCriteria.php',
  746         'CDbExpression' => '/db/schema/CDbExpression.php',
  747         'CDbSchema' => '/db/schema/CDbSchema.php',
  748         'CDbTableSchema' => '/db/schema/CDbTableSchema.php',
  749         'CCubridColumnSchema' => '/db/schema/cubrid/CCubridColumnSchema.php',
  750         'CCubridSchema' => '/db/schema/cubrid/CCubridSchema.php',
  751         'CCubridTableSchema' => '/db/schema/cubrid/CCubridTableSchema.php',
  752         'CMssqlColumnSchema' => '/db/schema/mssql/CMssqlColumnSchema.php',
  753         'CMssqlCommandBuilder' => '/db/schema/mssql/CMssqlCommandBuilder.php',
  754         'CMssqlPdoAdapter' => '/db/schema/mssql/CMssqlPdoAdapter.php',
  755         'CMssqlSchema' => '/db/schema/mssql/CMssqlSchema.php',
  756         'CMssqlSqlsrvPdoAdapter' => '/db/schema/mssql/CMssqlSqlsrvPdoAdapter.php',
  757         'CMssqlTableSchema' => '/db/schema/mssql/CMssqlTableSchema.php',
  758         'CMysqlColumnSchema' => '/db/schema/mysql/CMysqlColumnSchema.php',
  759         'CMysqlCommandBuilder' => '/db/schema/mysql/CMysqlCommandBuilder.php',
  760         'CMysqlSchema' => '/db/schema/mysql/CMysqlSchema.php',
  761         'CMysqlTableSchema' => '/db/schema/mysql/CMysqlTableSchema.php',
  762         'COciColumnSchema' => '/db/schema/oci/COciColumnSchema.php',
  763         'COciCommandBuilder' => '/db/schema/oci/COciCommandBuilder.php',
  764         'COciSchema' => '/db/schema/oci/COciSchema.php',
  765         'COciTableSchema' => '/db/schema/oci/COciTableSchema.php',
  766         'CPgsqlColumnSchema' => '/db/schema/pgsql/CPgsqlColumnSchema.php',
  767         'CPgsqlCommandBuilder' => '/db/schema/pgsql/CPgsqlCommandBuilder.php',
  768         'CPgsqlSchema' => '/db/schema/pgsql/CPgsqlSchema.php',
  769         'CPgsqlTableSchema' => '/db/schema/pgsql/CPgsqlTableSchema.php',
  770         'CSqliteColumnSchema' => '/db/schema/sqlite/CSqliteColumnSchema.php',
  771         'CSqliteCommandBuilder' => '/db/schema/sqlite/CSqliteCommandBuilder.php',
  772         'CSqliteSchema' => '/db/schema/sqlite/CSqliteSchema.php',
  773         'CChoiceFormat' => '/i18n/CChoiceFormat.php',
  774         'CDateFormatter' => '/i18n/CDateFormatter.php',
  775         'CDbMessageSource' => '/i18n/CDbMessageSource.php',
  776         'CGettextMessageSource' => '/i18n/CGettextMessageSource.php',
  777         'CLocale' => '/i18n/CLocale.php',
  778         'CMessageSource' => '/i18n/CMessageSource.php',
  779         'CNumberFormatter' => '/i18n/CNumberFormatter.php',
  780         'CPhpMessageSource' => '/i18n/CPhpMessageSource.php',
  781         'CGettextFile' => '/i18n/gettext/CGettextFile.php',
  782         'CGettextMoFile' => '/i18n/gettext/CGettextMoFile.php',
  783         'CGettextPoFile' => '/i18n/gettext/CGettextPoFile.php',
  784         'CChainedLogFilter' => '/logging/CChainedLogFilter.php',
  785         'CDbLogRoute' => '/logging/CDbLogRoute.php',
  786         'CEmailLogRoute' => '/logging/CEmailLogRoute.php',
  787         'CFileLogRoute' => '/logging/CFileLogRoute.php',
  788         'CLogFilter' => '/logging/CLogFilter.php',
  789         'CLogRoute' => '/logging/CLogRoute.php',
  790         'CLogRouter' => '/logging/CLogRouter.php',
  791         'CLogger' => '/logging/CLogger.php',
  792         'CProfileLogRoute' => '/logging/CProfileLogRoute.php',
  793         'CSysLogRoute' => '/logging/CSysLogRoute.php',
  794         'CWebLogRoute' => '/logging/CWebLogRoute.php',
  795         'CDateTimeParser' => '/utils/CDateTimeParser.php',
  796         'CFileHelper' => '/utils/CFileHelper.php',
  797         'CFormatter' => '/utils/CFormatter.php',
  798         'CLocalizedFormatter' => '/utils/CLocalizedFormatter.php',
  799         'CMarkdownParser' => '/utils/CMarkdownParser.php',
  800         'CPasswordHelper' => '/utils/CPasswordHelper.php',
  801         'CPropertyValue' => '/utils/CPropertyValue.php',
  802         'CTimestamp' => '/utils/CTimestamp.php',
  803         'CVarDumper' => '/utils/CVarDumper.php',
  804         'CBooleanValidator' => '/validators/CBooleanValidator.php',
  805         'CCaptchaValidator' => '/validators/CCaptchaValidator.php',
  806         'CCompareValidator' => '/validators/CCompareValidator.php',
  807         'CDateValidator' => '/validators/CDateValidator.php',
  808         'CDefaultValueValidator' => '/validators/CDefaultValueValidator.php',
  809         'CEmailValidator' => '/validators/CEmailValidator.php',
  810         'CExistValidator' => '/validators/CExistValidator.php',
  811         'CFileValidator' => '/validators/CFileValidator.php',
  812         'CFilterValidator' => '/validators/CFilterValidator.php',
  813         'CInlineValidator' => '/validators/CInlineValidator.php',
  814         'CNumberValidator' => '/validators/CNumberValidator.php',
  815         'CRangeValidator' => '/validators/CRangeValidator.php',
  816         'CRegularExpressionValidator' => '/validators/CRegularExpressionValidator.php',
  817         'CRequiredValidator' => '/validators/CRequiredValidator.php',
  818         'CSafeValidator' => '/validators/CSafeValidator.php',
  819         'CStringValidator' => '/validators/CStringValidator.php',
  820         'CTypeValidator' => '/validators/CTypeValidator.php',
  821         'CUniqueValidator' => '/validators/CUniqueValidator.php',
  822         'CUnsafeValidator' => '/validators/CUnsafeValidator.php',
  823         'CUrlValidator' => '/validators/CUrlValidator.php',
  824         'CValidator' => '/validators/CValidator.php',
  825         'CActiveDataProvider' => '/web/CActiveDataProvider.php',
  826         'CArrayDataProvider' => '/web/CArrayDataProvider.php',
  827         'CAssetManager' => '/web/CAssetManager.php',
  828         'CBaseController' => '/web/CBaseController.php',
  829         'CCacheHttpSession' => '/web/CCacheHttpSession.php',
  830         'CClientScript' => '/web/CClientScript.php',
  831         'CController' => '/web/CController.php',
  832         'CDataProvider' => '/web/CDataProvider.php',
  833         'CDataProviderIterator' => '/web/CDataProviderIterator.php',
  834         'CDbHttpSession' => '/web/CDbHttpSession.php',
  835         'CExtController' => '/web/CExtController.php',
  836         'CFormModel' => '/web/CFormModel.php',
  837         'CHttpCookie' => '/web/CHttpCookie.php',
  838         'CHttpRequest' => '/web/CHttpRequest.php',
  839         'CHttpSession' => '/web/CHttpSession.php',
  840         'CHttpSessionIterator' => '/web/CHttpSessionIterator.php',
  841         'COutputEvent' => '/web/COutputEvent.php',
  842         'CPagination' => '/web/CPagination.php',
  843         'CSort' => '/web/CSort.php',
  844         'CSqlDataProvider' => '/web/CSqlDataProvider.php',
  845         'CTheme' => '/web/CTheme.php',
  846         'CThemeManager' => '/web/CThemeManager.php',
  847         'CUploadedFile' => '/web/CUploadedFile.php',
  848         'CUrlManager' => '/web/CUrlManager.php',
  849         'CWebApplication' => '/web/CWebApplication.php',
  850         'CWebModule' => '/web/CWebModule.php',
  851         'CWidgetFactory' => '/web/CWidgetFactory.php',
  852         'CAction' => '/web/actions/CAction.php',
  853         'CInlineAction' => '/web/actions/CInlineAction.php',
  854         'CViewAction' => '/web/actions/CViewAction.php',
  855         'CAccessControlFilter' => '/web/auth/CAccessControlFilter.php',
  856         'CAuthAssignment' => '/web/auth/CAuthAssignment.php',
  857         'CAuthItem' => '/web/auth/CAuthItem.php',
  858         'CAuthManager' => '/web/auth/CAuthManager.php',
  859         'CBaseUserIdentity' => '/web/auth/CBaseUserIdentity.php',
  860         'CDbAuthManager' => '/web/auth/CDbAuthManager.php',
  861         'CPhpAuthManager' => '/web/auth/CPhpAuthManager.php',
  862         'CUserIdentity' => '/web/auth/CUserIdentity.php',
  863         'CWebUser' => '/web/auth/CWebUser.php',
  864         'CFilter' => '/web/filters/CFilter.php',
  865         'CFilterChain' => '/web/filters/CFilterChain.php',
  866         'CHttpCacheFilter' => '/web/filters/CHttpCacheFilter.php',
  867         'CInlineFilter' => '/web/filters/CInlineFilter.php',
  868         'CForm' => '/web/form/CForm.php',
  869         'CFormButtonElement' => '/web/form/CFormButtonElement.php',
  870         'CFormElement' => '/web/form/CFormElement.php',
  871         'CFormElementCollection' => '/web/form/CFormElementCollection.php',
  872         'CFormInputElement' => '/web/form/CFormInputElement.php',
  873         'CFormStringElement' => '/web/form/CFormStringElement.php',
  874         'CGoogleApi' => '/web/helpers/CGoogleApi.php',
  875         'CHtml' => '/web/helpers/CHtml.php',
  876         'CJSON' => '/web/helpers/CJSON.php',
  877         'CJavaScript' => '/web/helpers/CJavaScript.php',
  878         'CJavaScriptExpression' => '/web/helpers/CJavaScriptExpression.php',
  879         'CPradoViewRenderer' => '/web/renderers/CPradoViewRenderer.php',
  880         'CViewRenderer' => '/web/renderers/CViewRenderer.php',
  881         'CWebService' => '/web/services/CWebService.php',
  882         'CWebServiceAction' => '/web/services/CWebServiceAction.php',
  883         'CWsdlGenerator' => '/web/services/CWsdlGenerator.php',
  884         'CActiveForm' => '/web/widgets/CActiveForm.php',
  885         'CAutoComplete' => '/web/widgets/CAutoComplete.php',
  886         'CClipWidget' => '/web/widgets/CClipWidget.php',
  887         'CContentDecorator' => '/web/widgets/CContentDecorator.php',
  888         'CFilterWidget' => '/web/widgets/CFilterWidget.php',
  889         'CFlexWidget' => '/web/widgets/CFlexWidget.php',
  890         'CHtmlPurifier' => '/web/widgets/CHtmlPurifier.php',
  891         'CInputWidget' => '/web/widgets/CInputWidget.php',
  892         'CMarkdown' => '/web/widgets/CMarkdown.php',
  893         'CMaskedTextField' => '/web/widgets/CMaskedTextField.php',
  894         'CMultiFileUpload' => '/web/widgets/CMultiFileUpload.php',
  895         'COutputCache' => '/web/widgets/COutputCache.php',
  896         'COutputProcessor' => '/web/widgets/COutputProcessor.php',
  897         'CStarRating' => '/web/widgets/CStarRating.php',
  898         'CTabView' => '/web/widgets/CTabView.php',
  899         'CTextHighlighter' => '/web/widgets/CTextHighlighter.php',
  900         'CTreeView' => '/web/widgets/CTreeView.php',
  901         'CWidget' => '/web/widgets/CWidget.php',
  902         'CCaptcha' => '/web/widgets/captcha/CCaptcha.php',
  903         'CCaptchaAction' => '/web/widgets/captcha/CCaptchaAction.php',
  904         'CBasePager' => '/web/widgets/pagers/CBasePager.php',
  905         'CLinkPager' => '/web/widgets/pagers/CLinkPager.php',
  906         'CListPager' => '/web/widgets/pagers/CListPager.php',
  907     );
  908 }
  909 
  910 spl_autoload_register(array('YiiBase','autoload'));
  911 require(YII_PATH.'/base/interfaces.php');