Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • Yii
  • YiiBase
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Yii bootstrap 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: require(dirname(__FILE__).'/YiiBase.php');
 14: 
 15: /**
 16:  * Yii is a helper class serving common framework functionalities.
 17:  *
 18:  * It encapsulates {@link YiiBase} which provides the actual implementation.
 19:  * By writing your own Yii class, you can customize some functionalities of YiiBase.
 20:  *
 21:  * @author Qiang Xue <qiang.xue@gmail.com>
 22:  * @package system
 23:  * @since 1.0
 24:  */
 25: class Yii extends YiiBase
 26: {
 27:     public static $paths = array();
 28:     public static $systemuser;
 29:     public static $translationLog = array();
 30:     protected static $rootPath;
 31: 
 32:     /**
 33:      * Copied from CHttpRequest. Allows us to remove getRootPath's dependency on request component
 34:      * This method is Copyright (c) 2008-2014 by Yii Software LLC
 35:      * http://www.yiiframework.com/license/  
 36:      */
 37:     private static $_scriptFile;
 38:     private static function getScriptFile()
 39:     {
 40:         if(self::$_scriptFile!==null)
 41:             return self::$_scriptFile;
 42:         else
 43:             return self::$_scriptFile=realpath($_SERVER['SCRIPT_FILENAME']);
 44:     }
 45: 
 46:     /**
 47:      * Precondition: Request component has already been created. If it hasn't, infinite recursion 
 48:      * will occur when Yii::app()->getRequest () is called implicitly by self::app()->request.
 49:      */
 50:     public static function getRootPath() {
 51:         if (YII_UNIT_TESTING) { 
 52:             // resets root path to the webroot so that custom files can be detected
 53:             $path = array ();
 54:             exec ('pwd', $path);
 55:             self::$rootPath = dirname (preg_replace ('/\/tests/', '', $path[0]));
 56:         } elseif (!isset(self::$rootPath)) {
 57:             self::$rootPath = dirname(self::getScriptFile ());
 58:         }
 59: 
 60:         return self::$rootPath;
 61:     }
 62: 
 63:     /**
 64:      * Extends {@link YiiBase::createWebApplication()} to use X2WebApplication
 65:      * @param mixed $config application configuration.
 66:      * @return X2WebApplication
 67:      */
 68:     public static function createWebApplication($config=null) {
 69:         require(implode(DIRECTORY_SEPARATOR,array(
 70:             __DIR__,
 71:             '..',
 72:             'protected',
 73:             'components',
 74:             'X2WebApplication.php'
 75:         )));
 76:         return parent::createApplication('X2WebApplication',$config);
 77:     }
 78: 
 79:     /**
 80:      * Checks if a custom version of a file exists
 81:      *
 82:      * @param String $path The file path
 83:      * @return String $path The original file path, or the version in /custom if it exists
 84:      */
 85:     public static function getCustomPath($path) {
 86:         //calculate equivalent path in /custom, ie. from [root]/[path] to [root]/custom/[path]
 87:         $customPath = str_replace(
 88:             self::getRootPath(),self::getRootPath().DIRECTORY_SEPARATOR.'custom',$path);
 89: 
 90:         if(file_exists($customPath))
 91:             $path = $customPath;
 92:         return $path;
 93:     }
 94: 
 95:     /**
 96:      * Checks if a custom version of a class file exists
 97:      *
 98:      * @param String $path The path to something in /custom
 99:      * @return String $path The path to the original file or folder
100:      */
101:     public static function resetCustomPath($customPath) {
102:         return str_replace(
103:             self::getRootPath().DIRECTORY_SEPARATOR.'custom',self::getRootPath(),$customPath);
104:     }
105: 
106:     /**
107:      * Modified to check custom paths
108:      * This method is Copyright (c) 2008-2014 by Yii Software LLC
109:      * http://www.yiiframework.com/license/ 
110:      */
111:     public static function import($alias,$forceInclude=false)
112:     {
113:         if(isset(self::$_imports[$alias]))  // previously imported
114:             return self::$_imports[$alias];
115: 
116:         if(class_exists($alias,false) || interface_exists($alias,false))
117:             return self::$_imports[$alias]=$alias;
118: 
119:         if(($pos=strrpos($alias,'\\'))!==false) // a class name in PHP 5.3 namespace format
120:         {
121:             $namespace=str_replace('\\','.',ltrim(substr($alias,0,$pos),'\\'));
122:             if(($path=self::getPathOfAlias($namespace))!==false)
123:             {
124:                 $classFile=$path.DIRECTORY_SEPARATOR.substr($alias,$pos+1).'.php';
125:                 if($forceInclude)
126:                 {
127:                     if(is_file($classFile))
128:                         /* x2modstart */  
129:                         require(self::getCustomPath ($classFile));
130:                         /* x2modend */ 
131:                     else
132:                         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)));
133:                     self::$_imports[$alias]=$alias;
134:                 }
135:                 else
136:                     self::$classMap[$alias]=$classFile;
137:                 return $alias;
138:             }
139:             else
140:             {
141:                 // try to autoload the class with an autoloader
142:                 if (class_exists($alias,true))
143:                     return self::$_imports[$alias]=$alias;
144:                 else
145:                     throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
146:                         array('{alias}'=>$namespace)));
147:             }
148:         }
149: 
150:         if(($pos=strrpos($alias,'.'))===false)  // a simple class name
151:         {
152:             // try to autoload the class with an autoloader if $forceInclude is true
153:             /* x2modstart */     
154:             if($forceInclude && (self::x2_autoload($alias,true) || class_exists($alias,true)))
155:             /* x2modend */    
156:                 self::$_imports[$alias]=$alias;
157:             return $alias;
158:         }
159: 
160:         $className=(string)substr($alias,$pos+1);
161:         $isClass=$className!=='*';
162: 
163:         if($isClass && (class_exists($className,false) || interface_exists($className,false)))
164:             return self::$_imports[$alias]=$className;
165: 
166:         if(($path=self::getPathOfAlias($alias))!==false)
167:         {
168:             if($isClass)
169:             {
170:                 if($forceInclude)
171:                 {
172:                     if(is_file($path.'.php'))
173:                         /* x2modstart */ 
174:                         require(self::getCustomPath ($path.'.php'));
175:                         /* x2modend */ 
176:                     else
177:                         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)));
178:                     self::$_imports[$alias]=$className;
179:                 }
180:                 else
181:                     self::$classMap[$className]=$path.'.php';
182:                 return $className;
183:             }
184:             else  // a directory
185:             {
186:                 if(self::$_includePaths===null)
187:                 {
188:                     self::$_includePaths=array_unique(explode(PATH_SEPARATOR,get_include_path()));
189:                     if(($pos=array_search('.',self::$_includePaths,true))!==false)
190:                         unset(self::$_includePaths[$pos]);
191:                 }
192: 
193:                 array_unshift(self::$_includePaths,$path);
194: 
195:                 if(self::$enableIncludePath && set_include_path('.'.PATH_SEPARATOR.implode(PATH_SEPARATOR,self::$_includePaths))===false)
196:                     self::$enableIncludePath=false;
197: 
198:                 return self::$_imports[$alias]=$path;
199:             }
200:         }
201:         else
202:             throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
203:                 array('{alias}'=>$alias)));
204:     }
205: 
206:     /**
207:      * Added custom path checking
208:      * This method is Copyright (c) 2008-2014 by Yii Software LLC
209:      * http://www.yiiframework.com/license/ 
210:      */
211:     public static function x2_autoload($className,$classMapOnly=false)
212:     {
213:         // use include so that the error PHP file may appear
214:         if(isset(self::$classMap[$className]))
215:             /* x2modstart */  
216:             include(self::getCustomPath(self::$classMap[$className]));
217:             /* x2modend */ 
218:         elseif(isset(self::$_coreClasses[$className]))
219:             include(YII_PATH.self::$_coreClasses[$className]);
220:         elseif($classMapOnly)
221:             return false;
222:         else
223:         {
224:             // include class file relying on include_path
225:             if(strpos($className,'\\')===false)  // class without namespace
226:             {
227:                 if(self::$enableIncludePath===false)
228:                 {
229:                     foreach(self::$_includePaths as $path)
230:                     {
231:                         $classFile=$path.DIRECTORY_SEPARATOR.$className.'.php';
232:                         if(is_file($classFile))
233:                         {
234:                             /* x2modstart */     
235:                             include(self::getCustomPath ($classFile));
236:                             /* x2modend */ 
237:                             if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php')
238:                                 throw new CException(Yii::t('yii','Class name "{class}" does not match class file "{file}".', array(
239:                                     '{class}'=>$className,
240:                                     '{file}'=>$classFile,
241:                                 )));
242:                             break;
243:                         }
244:                     }
245:                 }
246:                 else
247:                     /* x2modstart */ 
248:                     include(self::getCustomPath ($className.'.php'));
249:                     /* x2modend */ 
250:             }
251:             else  // class name with namespace in PHP 5.3
252:             {
253:                 $namespace=str_replace('\\','.',ltrim($className,'\\'));
254:                 if(($path=self::getPathOfAlias($namespace))!==false)
255:                     /* x2modstart */ 
256:                     include(self::getCustomPath ($path.'.php'));
257:                     /* x2modend */ 
258:                 else
259:                     return false;
260:             }
261:             return class_exists($className,false) || interface_exists($className,false);
262:         }
263:         return true;
264:     }
265: 
266:     public static function t($category,$message,$params=array(),$source=null,$language=null) {
267:         X2_TRANSLATION_LOGGING && Yii::logTranslation($category, $message);
268:         if(isset($_GET['t']) && $_GET['t'])
269:             return '<dt class="yii-t">'
270:                 .CHtml::hiddenField('cat',$category)
271:                 .CHtml::hiddenField('msg',$message)
272:                 .parent::t($category,$message,$params,$source,$language)
273:                 .'</dt>';
274: 
275:         else
276:             return parent::t($category,$message,$params,$source,$language);
277:     }
278:         
279:     public static function logTranslation($category, $message){
280:         if(!isset(Yii::$translationLog[$category])){
281:             Yii::$translationLog[$category] = array();
282:         }
283:         Yii::$translationLog[$category][$message] = '';
284:     }
285: 
286: }
287: 
API documentation generated by ApiGen 2.8.0