PageRenderTime 184ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 2ms

/protected/test.txt

http://github.com/phpnode/YiiJS
Plain Text | 13930 lines | 13545 code | 385 blank | 0 comment | 0 complexity | 29c971761f8a835f00acf162c4fa918b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*global php, $, jQuery, alert, clearInterval, clearTimeout, document, event, frames, history, Image, location, name, navigator, Option, parent, screen, setInterval, setTimeout, window, XMLHttpRequest */
  2. /**
  3. * Yii is a helper class serving common framework functionalities.
  4. *
  5. * It encapsulates {@link YiiBase} which provides the actual implementation.
  6. * By writing your own Yii class, you can customize some functionalities of YiiBase.
  7. *
  8. * @originalAuthor Qiang Xue <qiang.xue@gmail.com>
  9. * @version $Id: yii.js 2799 2011-01-01 19:31:13Z qiang.xue $
  10. * @package system
  11. * @since 1.0
  12. * @author Charles Pick
  13. * @class
  14. * @extends Yii.YiiBase
  15. */
  16. var YII_DEBUG = true, YII_TRACE_LEVEL = 3, YII_BEGIN_TIME = new Date().getTime() / 1000, Yii = /** @lends Yii.prototype */{
  17. /**
  18. * @property {Array} class map used by the Yii autoloading mechanism.
  19. * The array keys are the class names and the array values are the corresponding class file paths.
  20. * @since 1.1.5
  21. */
  22. classMap: {},
  23. _aliases: {},
  24. _imports: {},
  25. _includePaths: {},
  26. _app: null,
  27. _logger: null,
  28. /**
  29. * @property {Array} class map for core Yii classes.
  30. * NOTE, DO NOT MODIFY THIS ARRAY MANUALLY. IF YOU CHANGE OR ADD SOME CORE CLASSES,
  31. * PLEASE RUN 'build autoload' COMMAND TO UPDATE THIS ARRAY.
  32. */
  33. _coreClasses: {'CApplication':'/base/CApplication.js','CApplicationComponent':'/base/CApplicationComponent.js','CBehavior':'/base/CBehavior.js','CComponent':'/base/CComponent.js','CErrorEvent':'/base/CErrorEvent.js','CErrorHandler':'/base/CErrorHandler.js','CException':'/base/CException.js','CExceptionEvent':'/base/CExceptionEvent.js','CHttpException':'/base/CHttpException.js','CModel':'/base/CModel.js','CModelBehavior':'/base/CModelBehavior.js','CModelEvent':'/base/CModelEvent.js','CModule':'/base/CModule.js','CSecurityManager':'/base/CSecurityManager.js','CStatePersister':'/base/CStatePersister.js','CApcCache':'/caching/CApcCache.js','CCache':'/caching/CCache.js','CDbCache':'/caching/CDbCache.js','CDummyCache':'/caching/CDummyCache.js','CEAcceleratorCache':'/caching/CEAcceleratorCache.js','CFileCache':'/caching/CFileCache.js','CMemCache':'/caching/CMemCache.js','CWinCache':'/caching/CWinCache.js','CXCache':'/caching/CXCache.js','CZendDataCache':'/caching/CZendDataCache.js','CCacheDependency':'/caching/dependencies/CCacheDependency.js','CChainedCacheDependency':'/caching/dependencies/CChainedCacheDependency.js','CDbCacheDependency':'/caching/dependencies/CDbCacheDependency.js','CDirectoryCacheDependency':'/caching/dependencies/CDirectoryCacheDependency.js','CExpressionDependency':'/caching/dependencies/CExpressionDependency.js','CFileCacheDependency':'/caching/dependencies/CFileCacheDependency.js','CGlobalStateCacheDependency':'/caching/dependencies/CGlobalStateCacheDependency.js','CAttributeCollection':'/collections/CAttributeCollection.js','CConfiguration':'/collections/CConfiguration.js','CList':'/collections/CList.js','CListIterator':'/collections/CListIterator.js','CMap':'/collections/CMap.js','CMapIterator':'/collections/CMapIterator.js','CQueue':'/collections/CQueue.js','CQueueIterator':'/collections/CQueueIterator.js','CStack':'/collections/CStack.js','CStackIterator':'/collections/CStackIterator.js','CTypedList':'/collections/CTypedList.js','CTypedMap':'/collections/CTypedMap.js','CConsoleApplication':'/console/CConsoleApplication.js','CConsoleCommand':'/console/CConsoleCommand.js','CConsoleCommandRunner':'/console/CConsoleCommandRunner.js','CHelpCommand':'/console/CHelpCommand.js','CDbCommand':'/db/CDbCommand.js','CDbConnection':'/db/CDbConnection.js','CDbDataReader':'/db/CDbDataReader.js','CDbException':'/db/CDbException.js','CDbMigration':'/db/CDbMigration.js','CDbTransaction':'/db/CDbTransaction.js','CActiveFinder':'/db/ar/CActiveFinder.js','CActiveRecord':'/db/ar/CActiveRecord.js','CActiveRecordBehavior':'/db/ar/CActiveRecordBehavior.js','CDbColumnSchema':'/db/schema/CDbColumnSchema.js','CDbCommandBuilder':'/db/schema/CDbCommandBuilder.js','CDbCriteria':'/db/schema/CDbCriteria.js','CDbExpression':'/db/schema/CDbExpression.js','CDbSchema':'/db/schema/CDbSchema.js','CDbTableSchema':'/db/schema/CDbTableSchema.js','CMssqlColumnSchema':'/db/schema/mssql/CMssqlColumnSchema.js','CMssqlCommandBuilder':'/db/schema/mssql/CMssqlCommandBuilder.js','CMssqlPdoAdapter':'/db/schema/mssql/CMssqlPdoAdapter.js','CMssqlSchema':'/db/schema/mssql/CMssqlSchema.js','CMssqlTableSchema':'/db/schema/mssql/CMssqlTableSchema.js','CMysqlColumnSchema':'/db/schema/mysql/CMysqlColumnSchema.js','CMysqlSchema':'/db/schema/mysql/CMysqlSchema.js','CMysqlTableSchema':'/db/schema/mysql/CMysqlTableSchema.js','COciColumnSchema':'/db/schema/oci/COciColumnSchema.js','COciCommandBuilder':'/db/schema/oci/COciCommandBuilder.js','COciSchema':'/db/schema/oci/COciSchema.js','COciTableSchema':'/db/schema/oci/COciTableSchema.js','CPgsqlColumnSchema':'/db/schema/pgsql/CPgsqlColumnSchema.js','CPgsqlSchema':'/db/schema/pgsql/CPgsqlSchema.js','CPgsqlTableSchema':'/db/schema/pgsql/CPgsqlTableSchema.js','CSqliteColumnSchema':'/db/schema/sqlite/CSqliteColumnSchema.js','CSqliteCommandBuilder':'/db/schema/sqlite/CSqliteCommandBuilder.js','CSqliteSchema':'/db/schema/sqlite/CSqliteSchema.js','CChoiceFormat':'/i18n/CChoiceFormat.js','CDateFormatter':'/i18n/CDateFormatter.js','CDbMessageSource':'/i18n/CDbMessageSource.js','CGettextMessageSource':'/i18n/CGettextMessageSource.js','CLocale':'/i18n/CLocale.js','CMessageSource':'/i18n/CMessageSource.js','CNumberFormatter':'/i18n/CNumberFormatter.js','CPhpMessageSource':'/i18n/CPhpMessageSource.js','CGettextFile':'/i18n/gettext/CGettextFile.js','CGettextMoFile':'/i18n/gettext/CGettextMoFile.js','CGettextPoFile':'/i18n/gettext/CGettextPoFile.js','CDbLogRoute':'/logging/CDbLogRoute.js','CEmailLogRoute':'/logging/CEmailLogRoute.js','CFileLogRoute':'/logging/CFileLogRoute.js','CLogFilter':'/logging/CLogFilter.js','CLogRoute':'/logging/CLogRoute.js','CLogRouter':'/logging/CLogRouter.js','CLogger':'/logging/CLogger.js','CProfileLogRoute':'/logging/CProfileLogRoute.js','CWebLogRoute':'/logging/CWebLogRoute.js','CDateTimeParser':'/utils/CDateTimeParser.js','CFileHelper':'/utils/CFileHelper.js','CFormatter':'/utils/CFormatter.js','CMarkdownParser':'/utils/CMarkdownParser.js','CPropertyValue':'/utils/CPropertyValue.js','CTimestamp':'/utils/CTimestamp.js','CVarDumper':'/utils/CVarDumper.js','CBooleanValidator':'/validators/CBooleanValidator.js','CCaptchaValidator':'/validators/CCaptchaValidator.js','CCompareValidator':'/validators/CCompareValidator.js','CDateValidator':'/validators/CDateValidator.js','CDefaultValueValidator':'/validators/CDefaultValueValidator.js','CEmailValidator':'/validators/CEmailValidator.js','CExistValidator':'/validators/CExistValidator.js','CFileValidator':'/validators/CFileValidator.js','CFilterValidator':'/validators/CFilterValidator.js','CInlineValidator':'/validators/CInlineValidator.js','CNumberValidator':'/validators/CNumberValidator.js','CRangeValidator':'/validators/CRangeValidator.js','CRegularExpressionValidator':'/validators/CRegularExpressionValidator.js','CRequiredValidator':'/validators/CRequiredValidator.js','CSafeValidator':'/validators/CSafeValidator.js','CStringValidator':'/validators/CStringValidator.js','CTypeValidator':'/validators/CTypeValidator.js','CUniqueValidator':'/validators/CUniqueValidator.js','CUnsafeValidator':'/validators/CUnsafeValidator.js','CUrlValidator':'/validators/CUrlValidator.js','CValidator':'/validators/CValidator.js','CActiveDataProvider':'/web/CActiveDataProvider.js','CArrayDataProvider':'/web/CArrayDataProvider.js','CAssetManager':'/web/CAssetManager.js','CBaseController':'/web/CBaseController.js','CCacheHttpSession':'/web/CCacheHttpSession.js','CClientScript':'/web/CClientScript.js','CController':'/web/CController.js','CDataProvider':'/web/CDataProvider.js','CDbHttpSession':'/web/CDbHttpSession.js','CExtController':'/web/CExtController.js','CFormModel':'/web/CFormModel.js','CHttpCookie':'/web/CHttpCookie.js','CHttpRequest':'/web/CHttpRequest.js','CHttpSession':'/web/CHttpSession.js','CHttpSessionIterator':'/web/CHttpSessionIterator.js','COutputEvent':'/web/COutputEvent.js','CPagination':'/web/CPagination.js','CSort':'/web/CSort.js','CSqlDataProvider':'/web/CSqlDataProvider.js','CTheme':'/web/CTheme.js','CThemeManager':'/web/CThemeManager.js','CUploadedFile':'/web/CUploadedFile.js','CUrlManager':'/web/CUrlManager.js','CWebApplication':'/web/CWebApplication.js','CWebModule':'/web/CWebModule.js','CWidgetFactory':'/web/CWidgetFactory.js','CAction':'/web/actions/CAction.js','CInlineAction':'/web/actions/CInlineAction.js','CViewAction':'/web/actions/CViewAction.js','CAccessControlFilter':'/web/auth/CAccessControlFilter.js','CAuthAssignment':'/web/auth/CAuthAssignment.js','CAuthItem':'/web/auth/CAuthItem.js','CAuthManager':'/web/auth/CAuthManager.js','CBaseUserIdentity':'/web/auth/CBaseUserIdentity.js','CDbAuthManager':'/web/auth/CDbAuthManager.js','CPhpAuthManager':'/web/auth/CPhpAuthManager.js','CUserIdentity':'/web/auth/CUserIdentity.js','CWebUser':'/web/auth/CWebUser.js','CFilter':'/web/filters/CFilter.js','CFilterChain':'/web/filters/CFilterChain.js','CInlineFilter':'/web/filters/CInlineFilter.js','CForm':'/web/form/CForm.js','CFormButtonElement':'/web/form/CFormButtonElement.js','CFormElement':'/web/form/CFormElement.js','CFormElementCollection':'/web/form/CFormElementCollection.js','CFormInputElement':'/web/form/CFormInputElement.js','CFormStringElement':'/web/form/CFormStringElement.js','CGoogleApi':'/web/helpers/CGoogleApi.js','CHtml':'/web/helpers/CHtml.js','CJSON':'/web/helpers/CJSON.js','CJavaScript':'/web/helpers/CJavaScript.js','CPradoViewRenderer':'/web/renderers/CPradoViewRenderer.js','CViewRenderer':'/web/renderers/CViewRenderer.js','CWebService':'/web/services/CWebService.js','CWebServiceAction':'/web/services/CWebServiceAction.js','CWsdlGenerator':'/web/services/CWsdlGenerator.js','CActiveForm':'/web/widgets/CActiveForm.js','CAutoComplete':'/web/widgets/CAutoComplete.js','CClipWidget':'/web/widgets/CClipWidget.js','CContentDecorator':'/web/widgets/CContentDecorator.js','CFilterWidget':'/web/widgets/CFilterWidget.js','CFlexWidget':'/web/widgets/CFlexWidget.js','CHtmlPurifier':'/web/widgets/CHtmlPurifier.js','CInputWidget':'/web/widgets/CInputWidget.js','CMarkdown':'/web/widgets/CMarkdown.js','CMaskedTextField':'/web/widgets/CMaskedTextField.js','CMultiFileUpload':'/web/widgets/CMultiFileUpload.js','COutputCache':'/web/widgets/COutputCache.js','COutputProcessor':'/web/widgets/COutputProcessor.js','CStarRating':'/web/widgets/CStarRating.js','CTabView':'/web/widgets/CTabView.js','CTextHighlighter':'/web/widgets/CTextHighlighter.js','CTreeView':'/web/widgets/CTreeView.js','CWidget':'/web/widgets/CWidget.js','CCaptcha':'/web/widgets/captcha/CCaptcha.js','CCaptchaAction':'/web/widgets/captcha/CCaptchaAction.js','CBasePager':'/web/widgets/pagers/CBasePager.js','CLinkPager':'/web/widgets/pagers/CLinkPager.js','CListPager':'/web/widgets/pagers/CListPager.js'},
  34. /**
  35. * Augments a class with properties from another class
  36. * @param {Object} receivingClass The class that should be augmented
  37. * @param {Object} givingClass The class that donates the properties
  38. */
  39. augment: function (receivingClass, givingClass) {
  40. var methodName;
  41. for (methodName in givingClass.prototype) {
  42. if(!receivingClass.prototype[methodName]) {
  43. receivingClass.prototype[methodName] = givingClass.prototype[methodName];
  44. }
  45. }
  46. },
  47. /**
  48. * @returns {String} the version of Yii framework
  49. */
  50. getVersion: function () {
  51. return '1.1.8-dev';
  52. },
  53. /**
  54. * Creates a Web application instance.
  55. * @param {Mixed} config application configuration.
  56. * If a string, it is treated as the path of the file that contains the configuration;
  57. * If an array, it is the actual configuration information.
  58. * Please make sure you specify the {@link CApplication::basePath basePath} property in the configuration,
  59. * which should point to the directory containing all application logic, template and data.
  60. * If not, the directory will be defaulted to 'protected'.
  61. */
  62. createWebApplication: function (config) {
  63. if (config === undefined) {
  64. config = null;
  65. }
  66. return Yii.createApplication('CWebApplication',config);
  67. },
  68. /**
  69. * Creates a console application instance.
  70. * @param {Mixed} config application configuration.
  71. * If a string, it is treated as the path of the file that contains the configuration;
  72. * If an array, it is the actual configuration information.
  73. * Please make sure you specify the {@link CApplication::basePath basePath} property in the configuration,
  74. * which should point to the directory containing all application logic, template and data.
  75. * If not, the directory will be defaulted to 'protected'.
  76. */
  77. createConsoleApplication: function (config) {
  78. if (config === undefined) {
  79. config = null;
  80. }
  81. return Yii.createApplication('CConsoleApplication',config);
  82. },
  83. /**
  84. * Creates an application of the specified class.
  85. * @param {String} classVar the application class name
  86. * @param {Mixed} config application configuration. This parameter will be passed as the parameter
  87. * to the constructor of the application class.
  88. * @returns {Mixed} the application instance
  89. * @since 1.0.10
  90. */
  91. createApplication: function (classVar, config) {
  92. if (config === undefined) {
  93. config = null;
  94. }
  95. return new Yii[classVar](config);
  96. },
  97. /**
  98. * Returns the application singleton, null if the singleton has not been created yet.
  99. * @returns {Yii.CApplication} the application singleton, null if the singleton has not been created yet.
  100. */
  101. app: function () {
  102. return Yii._app;
  103. },
  104. /**
  105. * Stores the application instance in the class static member.
  106. * This method helps implement a singleton pattern for CApplication.
  107. * Repeated invocation of this method or the CApplication constructor
  108. * will cause the throw of an exception.
  109. * To retrieve the application instance, use {@link app()}.
  110. * @param {Yii.CApplication} app the application instance. If this is null, the existing
  111. * application singleton will be removed.
  112. * @throws {Yii.CException} if multiple application instances are registered.
  113. */
  114. setApplication: function (app) {
  115. var _app;
  116. if(Yii._app===null || app===null) {
  117. Yii._app=app;
  118. }
  119. else {
  120. throw new Yii.CException(Yii.t('yii','Yii application can only be created once.'));
  121. }
  122. },
  123. /**
  124. * @returns {String} the path of the framework
  125. */
  126. getFrameworkPath: function () {
  127. return YII_PATH;
  128. },
  129. /**
  130. * Creates an object and initializes it based on the given configuration.
  131. *
  132. * The specified configuration can be either a string or an array.
  133. * If the former, the string is treated as the object type which can
  134. * be either the class name or {@link Yii::getPathOfAlias class path alias}.
  135. * If the latter, the 'class' element is treated as the object type,
  136. * and the rest name-value pairs in the array are used to initialize
  137. * the corresponding object properties.
  138. *
  139. * Any additional parameters passed to this method will be
  140. * passed to the constructor of the object being created.
  141. *
  142. * NOTE: the array-typed configuration has been supported since version 1.0.1.
  143. *
  144. * @param {Mixed} config the configuration. It can be either a string or an array.
  145. * @returns {Mixed} the created object
  146. * @throws {Yii.CException} if the configuration does not have a 'class' element.
  147. */
  148. createComponent: function (config) {
  149. var type, n, args, object, classVar, key, value;
  150. if(typeof(config) === 'string') {
  151. type=config;
  152. config=[];
  153. }
  154. else if(config['class'] !== undefined) {
  155. type=config['class'];
  156. delete config['class'];
  157. }
  158. else {
  159. throw new Yii.CException(Yii.t('yii','Object configuration must be an array containing a "class" element.'));
  160. }
  161. if(!Yii[type]) {
  162. type=Yii.imports(type,true);
  163. }
  164. if((n=arguments.length)>1) {
  165. args=arguments;
  166. if(n===2) {
  167. object=new Yii[type](args[1]);
  168. }
  169. else if(n===3) {
  170. object=new Yii[type](args[1],args[2]);
  171. }
  172. else if(n===4) {
  173. object=new Yii[type](args[1],args[2],args[3]);
  174. }
  175. else if(n===4) {
  176. object=new Yii[type](args[1],args[2],args[3]);
  177. }
  178. else if(n===5) {
  179. object=new Yii[type](args[1],args[2],args[3],args[4]);
  180. }
  181. }
  182. else {
  183. object=new Yii[type]();
  184. }
  185. for (key in config) {
  186. if (config.hasOwnProperty(key)) {
  187. value = config[key];
  188. object.set(key,value);
  189. }
  190. }
  191. return object;
  192. },
  193. /**
  194. * Imports a class or a directory.
  195. *
  196. * Importing a class is like including the corresponding class file.
  197. * The main difference is that importing a class is much lighter because it only
  198. * includes the class file when the class is referenced the first time.
  199. *
  200. * Importing a directory is equivalent to adding a directory into the PHP include path.
  201. * If multiple directories are imported, the directories imported later will take
  202. * precedence in class file searching (i.e., they are added to the front of the PHP include path).
  203. *
  204. * Path aliases are used to import a class or directory. For example,
  205. * <ul>
  206. * <li><code>application.components.GoogleMap</code>: import the <code>GoogleMap</code> class.</li>
  207. * <li><code>application.components.*</code>: import the <code>components</code> directory.</li>
  208. * </ul>
  209. *
  210. * The same path alias can be imported multiple times, but only the first time is effective.
  211. * Importing a directory does not import any of its subdirectories.
  212. *
  213. * Starting from version 1.1.5, this method can also be used to import a class in namespace format
  214. * (available for PHP 5.3 or above only). It is similar to importing a class in path alias format,
  215. * except that the dot separator is replaced by the backslash separator. For example, importing
  216. * <code>application\components\GoogleMap</code> is similar to importing <code>application.components.GoogleMap</code>.
  217. * The difference is that the former class is using qualified name, while the latter unqualified.
  218. *
  219. * Note, importing a class in namespace format requires that the namespace is corresponding to
  220. * a valid path alias if we replace the backslash characters with dot characters.
  221. * For example, the namespace <code>application\components</code> must correspond to a valid
  222. * path alias <code>application.components</code>.
  223. *
  224. * @param {String} alias path alias to be imported
  225. * @param {Boolean} forceInclude whether to include the class file immediately. If false, the class file
  226. * will be included only when the class is being used. This parameter is used only when
  227. * the path alias refers to a class.
  228. * @returns {String} the class name or the directory that this alias refers to
  229. * @throws {Yii.CException} if the alias is invalid
  230. */
  231. imports: function (alias, forceInclude) {
  232. var result, _imports, pos, namespace, path, classFile, classMap, className, isClass, _includePaths;
  233. if (forceInclude === undefined) {
  234. forceInclude = true;
  235. }
  236. if(Yii._imports[alias] !== undefined) { // previously imported
  237. return Yii._imports[alias];
  238. }
  239. if(Yii[alias] !== undefined) {
  240. return (Yii._imports[alias]=alias);
  241. }
  242. if ((pos = alias.indexOf("/")) !== -1) {
  243. className = String(alias.split("/").pop());
  244. if (className.slice(-3) == ".js") {
  245. className = className.slice(0,-3);
  246. }
  247. if (Yii[className] !== undefined) {
  248. return (Yii._imports[alias] = className);
  249. }
  250. Yii.include(alias,!forceInclude);
  251. Yii.classMap[className] = alias;
  252. Yii._imports[alias] = className;
  253. return className;
  254. }
  255. if((pos=alias.indexOf('.'))===-1) { // a simple class name
  256. result = Yii.autoload(alias, !forceInclude);
  257. if(forceInclude && !result) {
  258. throw new Yii.CException(Yii.t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
  259. {'{alias}':alias}));
  260. }
  261. Yii._imports[alias]=alias;
  262. return alias;
  263. }
  264. className=String(alias.split(".").pop());
  265. isClass=className!=='*';
  266. if (!isClass) {
  267. throw new Yii.CException("YiiJS does not support importing directories");
  268. }
  269. if(Yii[className] !== undefined) {
  270. return (Yii._imports[alias]=className);
  271. }
  272. else if((path=Yii.getPathOfAlias(alias))!==false) {
  273. Yii.include(path + ".js",!forceInclude);
  274. Yii.classMap[className]=path+'.js';
  275. return className;
  276. }
  277. else {
  278. throw new Yii.CException(Yii.t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
  279. {'{alias}':alias}));
  280. }
  281. },
  282. /**
  283. * Translates an alias into a file path.
  284. * Note, this method does not ensure the existence of the resulting file path.
  285. * It only checks if the root alias is valid or not.
  286. * @param {String} alias alias (e.g. system.web.CController)
  287. * @returns {Mixed} file path corresponding to the alias, false if the alias is invalid.
  288. */
  289. getPathOfAlias: function (alias) {
  290. var _aliases, pos, rootAlias, _app;
  291. if(Yii._aliases[alias] !== undefined) {
  292. return Yii._aliases[alias];
  293. }
  294. else if((pos=php.strpos(alias,'.'))!==false) {
  295. rootAlias=alias.slice(0, pos);
  296. if(Yii._aliases[rootAlias] !== undefined) {
  297. return (Yii._aliases[alias]=php.rtrim(Yii._aliases[rootAlias]+'/'+php.str_replace('.','/',alias.slice(pos+1)),'*'+'/'));
  298. }
  299. else if(Yii._app !== null && Yii._app instanceof Yii.CWebApplication){
  300. if(Yii._app.findModule(rootAlias)!==null) {
  301. return Yii.getPathOfAlias(alias);
  302. }
  303. }
  304. }
  305. return false;
  306. },
  307. /**
  308. * Create a path alias.
  309. * Note, this method neither checks the existence of the path nor normalizes the path.
  310. * @param {String} alias alias to the path
  311. * @param {String} path the path corresponding to the alias. If this is null, the corresponding
  312. * path alias will be removed.
  313. */
  314. setPathOfAlias: function (alias, path) {
  315. var _aliases;
  316. if(php.empty(path)) {
  317. delete Yii._aliases[alias];
  318. }
  319. else {
  320. Yii._aliases[alias]=php.rtrim(path,'\\/');
  321. }
  322. },
  323. /**
  324. * Class autoload loader.
  325. * @param {String} className class name
  326. * @param {Boolean} async Whether to load this class
  327. * via an asynchronous AJAX request, otherwise a blocking request is used, defaults to false.
  328. * @returns {Boolean} whether the class has been loaded successfully
  329. */
  330. autoload: function (className, async) {
  331. var _coreClasses, classMap, namespace, path, result;
  332. if (async === undefined) {
  333. async = true;
  334. }
  335. if(Yii._coreClasses[className] !== undefined) {
  336. if (Yii[className] !== undefined) {
  337. return true;
  338. }
  339. result = Yii.include(YII_PATH+Yii._coreClasses[className], async);
  340. if (!async) {
  341. return result;
  342. }
  343. }
  344. else if(Yii.classMap[className] !== undefined) {
  345. if (Yii[className] !== undefined) {
  346. return true;
  347. }
  348. result = Yii.include(Yii.classMap[className], async);
  349. if (!async) {
  350. return result;
  351. }
  352. }
  353. else {
  354. return Yii[className] !== undefined;
  355. }
  356. return true;
  357. },
  358. /**
  359. * Includes a remote file, this will be evaled!
  360. * @param {String} url The URL to load the file from
  361. * @param {Boolean} async Whether to perform an asynchronous request or not, defaults to true.
  362. * @param {Function} callback The callback to execute after the included file is evaled
  363. * @returns {Mixed} either the jQuery ajax request if this is async, or
  364. * if this is a blocking request returns the content or false depending on whether
  365. * it succeeded or not.
  366. */
  367. include: function (url, async, callback) {
  368. var options = {}, request;
  369. if (async === undefined) {
  370. async = true;
  371. }
  372. if (callback === undefined) {
  373. callback = function () {};
  374. }
  375. if(Yii._includePaths[url] !== undefined) { // previously imported
  376. return Yii._includePaths[url];
  377. }
  378. options.url = url;
  379. options.async = async;
  380. options.cache = false;
  381. if (async) {
  382. options.success = function (res) {
  383. Yii._includePaths[url] = eval(res);
  384. callback(Yii._includePaths[url]);
  385. };
  386. options.error = function () {
  387. throw new Yii.CHttpException(404, Yii.t("system", "No such file"));
  388. };
  389. return jQuery.ajax(options);
  390. }
  391. else {
  392. request = jQuery.ajax(options);
  393. if (request.status > 399) {
  394. return false;
  395. }
  396. Yii._includePaths[url] = eval(request.responseText);
  397. callback(Yii._includePaths[url]);
  398. return Yii._includePaths[url];
  399. }
  400. },
  401. /**
  402. * Writes a trace message.
  403. * This method will only log a message when the application is in debug mode.
  404. * @param {String} msg message to be logged
  405. * @param {String} category category of the message
  406. * @see log
  407. */
  408. trace: function (msg, category) {
  409. if (category === undefined) {
  410. category = 'application';
  411. }
  412. if(YII_DEBUG) {
  413. Yii.log(msg,Yii.CLogger.prototype.LEVEL_TRACE,category);
  414. }
  415. },
  416. /**
  417. * Logs a message.
  418. * Messages logged by this method may be retrieved via {@link CLogger::getLogs}
  419. * and may be recorded in different media, such as file, email, database, using
  420. * {@link CLogRouter}.
  421. * @param {String} msg message to be logged
  422. * @param {String} level level of the message (e.g. 'trace', 'warning', 'error'). It is case-insensitive.
  423. * @param {String} category category of the message (e.g. 'system.web'). It is case-insensitive.
  424. */
  425. log: function (msg, level, category) {
  426. var _logger, traces, count, i, limit, trace, cmd;
  427. if (level === undefined) {
  428. level = 'info';
  429. }
  430. if (category === undefined) {
  431. category = 'application';
  432. }
  433. if(Yii._logger===null) {
  434. Yii._logger=new Yii.CLogger();
  435. }
  436. if(window['console'] !== undefined && YII_DEBUG && YII_TRACE_LEVEL>0 && level!==Yii.CLogger.prototype.LEVEL_PROFILE) {
  437. cmd = "log";
  438. if (level === Yii.CLogger.prototype.LEVEL_ERROR) {
  439. cmd = "error";
  440. }
  441. else if (level === Yii.CLogger.prototype.LEVEL_WARNING) {
  442. cmd = "warn";
  443. }
  444. console[cmd](level + "\t" + php.str_pad(category,30," ") + "\t" + msg);
  445. }
  446. Yii._logger.log(msg,level,category);
  447. },
  448. /**
  449. * Marks the begin of a code block for profiling.
  450. * This has to be matched with a call to {@link endProfile()} with the same token.
  451. * The begin- and end- calls must also be properly nested, e.g.,
  452. * <pre>
  453. * Yii.beginProfile('block1');
  454. * Yii.beginProfile('block2');
  455. * Yii.endProfile('block2');
  456. * Yii.endProfile('block1');
  457. * </pre>
  458. * The following sequence is not valid:
  459. * <pre>
  460. * Yii.beginProfile('block1');
  461. * Yii.beginProfile('block2');
  462. * Yii.endProfile('block1');
  463. * Yii.endProfile('block2');
  464. * </pre>
  465. * @param {String} token token for the code block
  466. * @param {String} category the category of this log message
  467. * @see endProfile
  468. */
  469. beginProfile: function (token, category) {
  470. if (category === undefined) {
  471. category = 'application';
  472. }
  473. Yii.log('begin:'+token,Yii.CLogger.prototype.LEVEL_PROFILE,category);
  474. },
  475. /**
  476. * Marks the end of a code block for profiling.
  477. * This has to be matched with a previous call to {@link beginProfile()} with the same token.
  478. * @param {String} token token for the code block
  479. * @param {String} category the category of this log message
  480. * @see beginProfile
  481. */
  482. endProfile: function (token, category) {
  483. if (category === undefined) {
  484. category = 'application';
  485. }
  486. Yii.log('end:'+token,Yii.CLogger.prototype.LEVEL_PROFILE,category);
  487. },
  488. /**
  489. * @returns {Yii.CLogger} message logger
  490. */
  491. getLogger: function () {
  492. var _logger;
  493. if(Yii._logger!==null) {
  494. return Yii._logger;
  495. }
  496. else {
  497. return (Yii._logger=new Yii.CLogger);
  498. }
  499. },
  500. /**
  501. * Returns a string that can be displayed on your Web page showing Powered-by-Yii information
  502. * @returns {String} a string that can be displayed on your Web page showing Powered-by-Yii information
  503. */
  504. powered: function () {
  505. return 'Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a>.';
  506. },
  507. /**
  508. * Translates a message to the specified language.
  509. * Starting from version 1.0.2, this method supports choice format (see {@link CChoiceFormat}),
  510. * i.e., the message returned will be chosen from a few candidates according to the given
  511. * number value. This feature is mainly used to solve plural format issue in case
  512. * a message has different plural forms in some languages.
  513. * @param {String} category message category. Please use only word letters. Note, category 'yii' is
  514. * reserved for Yii framework core code use. See {@link CPhpMessageSource} for
  515. * more interpretation about message category.
  516. * @param {String} message the original message
  517. * @param {Array} params parameters to be applied to the message using <code>strtr</code>.
  518. * Starting from version 1.0.2, the first parameter can be a number without key.
  519. * And in this case, the method will call {@link CChoiceFormat::format} to choose
  520. * an appropriate message translation.
  521. * Starting from version 1.1.6 you can pass parameter for {@link CChoiceFormat::format}
  522. * or plural forms format without wrapping it with array.
  523. * @param {String} source which message source application component to use.
  524. * Defaults to null, meaning using 'coreMessages' for messages belonging to
  525. * the 'yii' category and using 'messages' for the rest messages.
  526. * @param {String} language the target language. If null (default), the {@link CApplication::getLanguage application language} will be used.
  527. * This parameter has been available since version 1.0.3.
  528. * @returns {String} the translated message
  529. * @see CMessageSource
  530. */
  531. t: function (category, message, params, source, language) {
  532. var _app, chunks, expressions, n, i;
  533. if (params === undefined) {
  534. params = {};
  535. }
  536. if (source === undefined) {
  537. source = null;
  538. }
  539. if (language === undefined) {
  540. language = null;
  541. }
  542. if(Yii._app!==null) {
  543. if(source===null) {
  544. source=(category==='yii'||category==='zii')?'coreMessages':'messages';
  545. }
  546. if((source=Yii._app.getComponent(source))!==null && source !== undefined) {
  547. message=source.translate(category,message,language);
  548. }
  549. }
  550. if(params==={} || params === []) {
  551. return message;
  552. }
  553. if(params[0] !== undefined) {
  554. // number choice
  555. if(php.strpos(message,'|')!==false) {
  556. if(php.strpos(message,'#')===false) {
  557. chunks=message.split('|');
  558. expressions=Yii._app.getLocale(language).getPluralRules();
  559. n=php.min(php.count(chunks),php.count(expressions));
  560. if(n) {
  561. for(i=0;i<n;i++) {
  562. chunks[i]=expressions[i]+'#'+chunks[i];
  563. }
  564. message=chunks.join('|');
  565. }
  566. }
  567. message=Yii.CChoiceFormat.format(message,params[0]);
  568. }
  569. if(params['{n}'] === undefined) {
  570. params['{n}']=params[0];
  571. }
  572. delete params[0];
  573. }
  574. if (params !== {}) {
  575. return php.strtr(message,params);
  576. }
  577. return message;
  578. },
  579. /**
  580. * Registers a new class autoloader.
  581. * The new autoloader will be placed before {@link autoload} and after
  582. * any other existing autoloaders.
  583. * @param {Function} callback a valid PHP callback (function name or array($className,$methodName)).
  584. * @since 1.0.10
  585. */
  586. registerAutoloader: function (callback) {
  587. },
  588. /**
  589. * Removes JSDoc comments from a string
  590. * TODO: move this somewhere else
  591. * @param {String} str the string to strip
  592. * @returns {String} the stripped string
  593. */
  594. removeComments: function (str) {
  595. var uid = '_' + (new Date()),
  596. primatives = [],
  597. primIndex = 0;
  598. return (
  599. str
  600. .replace(/(['"])(\\\1|.)+?\1/g, function(match){
  601. primatives[primIndex] = match;
  602. return (uid + '') + primIndex++;
  603. })
  604. .replace(/([^\/])(\/(?!\*|\/)(\\\/|.)+?\/[gim]{0,3})/g, function(match, $1, $2){
  605. primatives[primIndex] = $2;
  606. return $1 + (uid + '') + primIndex++;
  607. })
  608. .replace(/\/\/.*?\/?\*.+?(?=\n|\r|$)|\/\*[\s\S]*?\/\/[\s\S]*?\*\//g, '')
  609. .replace(/\/\/.+?(?=\n|\r|$)|\/\*[\s\S]+?\*\//g, '')
  610. .replace(RegExp('\\/\\*[\\s\\S]+' + uid + '\\d+', 'g'), '')
  611. .replace(RegExp(uid + '(\\d+)', 'g'), function(match, n){
  612. return primatives[n];
  613. })
  614. );
  615. },
  616. /**
  617. * Similar to PHP's preg_match_all
  618. * @param {RegExp} regex The regular expression to match against
  619. * @param {String} haystack The string to perform the regex on
  620. * @returns {Array} an array of matches
  621. */
  622. matchAll: function (regex, haystack) {
  623. var matches = [], i, match;
  624. match = regex.exec(haystack);
  625. while (match !== null) {
  626. matches.push(match);
  627. match = regex.exec(haystack);
  628. }
  629. return matches;
  630. },
  631. /**
  632. * Extends a class
  633. */
  634. extend: function (childClass, parentClass, properties) {
  635. childClass.prototype = new Yii[parentClass](false);
  636. childClass.prototype.constructor = childClass;
  637. if (properties !== undefined) {
  638. Yii.forEach(properties, function(name, value) {
  639. childClass.prototype[name] = value;
  640. });
  641. }
  642. },
  643. /**
  644. * Implements foreach in JavaScript
  645. * @param {Mixed} itemList a list of items to iterate through
  646. * @param {Function} callback The callback function, it will recieve 2 parameters, key and value
  647. * if the callback returns false, the loop will break.
  648. */
  649. forEach: function (itemList, callback) {
  650. var i, limit;
  651. if (typeof itemList === "function") {
  652. return Yii.forEach(itemList(), callback);
  653. }
  654. if (Object.prototype.toString.call(itemList) === '[object Array]' || itemList instanceof Yii.CList || itemList instanceof Yii.CStack) {
  655. limit = itemList.length;
  656. for (i = 0; i < limit; i++) {
  657. if (i === "forEach") {
  658. continue;
  659. }
  660. else if (callback(i, itemList[i]) === false) {
  661. break;
  662. }
  663. }
  664. }
  665. else {
  666. for (i in itemList) {
  667. if (itemList.hasOwnProperty(i)) {
  668. if (i === "forEach") {
  669. continue;
  670. }
  671. else if (callback(i, itemList[i]) === false) {
  672. break;
  673. }
  674. }
  675. }
  676. }
  677. return itemList;
  678. },
  679. /**
  680. * Filter an array of items
  681. */
  682. filter: function (items, block) {
  683. var values = [];
  684. var thisp = arguments[1];
  685. for (var i = 0; i < items.length; i++)
  686. if (block.call(thisp, items[i]))
  687. values.push(items[i]);
  688. return values;
  689. }
  690. };
  691. /**
  692. * A shortcut to application properties.
  693. * Supports virtual getters and setters, e.g:
  694. * <pre>
  695. * $app("securityManager.validationKey") === Yii.app().getSecurityManager().getValidationKey();
  696. * </pre>
  697. */
  698. var $app = function(selector, setVal) {
  699. var stack, parts, i, limit, item, getter, last;
  700. if (selector === undefined || php.trim(selector).length === 0) {
  701. return Yii.app();
  702. }
  703. parts = selector.split(".");
  704. limit = parts.length;
  705. last = limit - 1;
  706. stack = Yii.app();
  707. for (i = 0; i < limit; i++) {
  708. if (stack instanceof Yii.CComponent) {
  709. if (setVal !== undefined) {
  710. return stack.set(parts.join("."),setVal);
  711. }
  712. return stack.get(parts.join("."));
  713. }
  714. item = parts.shift();
  715. if (i === last && setVal !== undefined) {
  716. if (stack[item] !== undefined) {
  717. stack[item] = setVal;
  718. return setVal;
  719. }
  720. else if (stack.get !== undefined) {
  721. stack = stack.set.call(stack, item, setVal);
  722. return setVal;
  723. }
  724. else {
  725. throw new Yii.CException("No such property: " + item);
  726. }
  727. }
  728. else {
  729. if (stack[item] !== undefined) {
  730. stack = stack[item];
  731. }
  732. else if (stack.get !== undefined) {
  733. stack = stack.get.call(stack, item);
  734. }
  735. else {
  736. throw new Yii.CException("No such property: " + item);
  737. }
  738. }
  739. }
  740. return stack;
  741. };/*global Yii, php, $, jQuery, alert, clearInterval, clearTimeout, document, event, frames, history, Image, location, name, navigator, Option, parent, screen, setInterval, setTimeout, window, XMLHttpRequest */
  742. /**
  743. * CComponent is the base class for all components.
  744. *
  745. * CComponent implements the protocol of defining, using properties and events.
  746. *
  747. * A property is defined by a getter method, and/or a setter method.
  748. * Properties can be accessed in the way like accessing normal object members.
  749. * Reading or writing a property will cause the invocation of the corresponding
  750. * getter or setter method, e.g
  751. * <pre>
  752. * a=component.text; // equivalent to $a=$component->getText();
  753. * component.text='abc'; // equivalent to $component->setText('abc');
  754. * </pre>
  755. * The signatures of getter and setter methods are as follows,
  756. * <pre>
  757. * // getter, defines a readable property 'text'
  758. * public function getText() { +++ }
  759. * // setter, defines a writable property 'text' with $value to be set to the property
  760. * public function setText(value) { +++ }
  761. * </pre>
  762. *
  763. * An event is defined by the presence of a method whose name starts with 'on'.
  764. * The event name is the method name. When an event is raised, functions
  765. * (called event handlers) attached to the event will be invoked automatically.
  766. *
  767. * An event can be raised by calling {@link raiseEvent} method, upon which
  768. * the attached event handlers will be invoked automatically in the order they
  769. * are attached to the event. Event handlers must have the following signature,
  770. * <pre>
  771. * function eventHandler(event) { +++ }
  772. * </pre>
  773. * where $event includes parameters associated with the event.
  774. *
  775. * To attach an event handler to an event, see {@link attachEventHandler}.
  776. * You can also use the following syntax:
  777. * <pre>
  778. * component.onClick=callback; // or $component->onClick->add($callback);
  779. * </pre>
  780. * where $callback refers to a valid PHP callback. Below we show some callback examples:
  781. * <pre>
  782. * 'handleOnClick' // handleOnClick() is a global function
  783. * [object,'handleOnClick'] // using $object->handleOnClick()
  784. * ['Page','handleOnClick'] // using Page::handleOnClick()
  785. * </pre>
  786. *
  787. * To raise an event, use {@link raiseEvent}. The on-method defining an event is
  788. * commonly written like the following:
  789. * <pre>
  790. * public function onClick(event)
  791. * {
  792. * this.raiseEvent('onClick',event);
  793. * }
  794. * </pre>
  795. * where <code>$event</code> is an instance of {@link CEvent} or its child class.
  796. * One can then raise the event by calling the on-method instead of {@link raiseEvent} directly.
  797. *
  798. * Both property names and event names are case-insensitive.
  799. *
  800. * Starting from version 1.0.2, CComponent supports behaviors. A behavior is an
  801. * instance of {@link IBehavior} which is attached to a component. The methods of
  802. * the behavior can be invoked as if they belong to the component. Multiple behaviors
  803. * can be attached to the same component.
  804. *
  805. * To attach a behavior to a component, call {@link attachBehavior}; and to detach the behavior
  806. * from the component, call {@link detachBehavior}.
  807. *
  808. * A behavior can be temporarily enabled or disabled by calling {@link enableBehavior}
  809. * or {@link disableBehavior}, respectively. When disabled, the behavior methods cannot
  810. * be invoked via the component.
  811. *
  812. * Starting from version 1.1.0, a behavior's properties (either its public member variables or
  813. * its properties defined via getters and/or setters) can be accessed through the component it
  814. * is attached to.
  815. *
  816. * @originalAuthor Qiang Xue <qiang.xue@gmail.com>
  817. * @version $Id: CComponent.php 3066 2011-03-13 14:22:55Z qiang.xue $
  818. * @package system.base
  819. * @since 1.0
  820. * @author Charles Pick
  821. * @class
  822. */
  823. Yii.CComponent = function CComponent() {
  824. };
  825. Yii.CComponent.prototype._e = null;
  826. Yii.CComponent.prototype._m = null;
  827. /**
  828. * Gets the class name for this item.
  829. * Since JavaScript doesn't really support this we
  830. * abuse function declarations to implement it,
  831. * for example instead of:
  832. * <pre>
  833. * Yii.Blah = function() { ... }
  834. * </pre>
  835. * we use:
  836. * <pre>
  837. * Yii.Blah = function Blah() { ... }
  838. * </pre>
  839. * We can now retrieve the name of the class by inspecting the constructor.
  840. */
  841. Yii.CComponent.prototype.getClassName = function() {
  842. var matches, className;
  843. matches = /function(.*)\((.*)\)/.exec((this).constructor);
  844. if (matches) {
  845. return php.trim(matches[1]);
  846. }
  847. };
  848. /**
  849. * Returns a property value, an event handler list or a behavior based on its name.
  850. * Do not call this method. This is a PHP magic method that we override
  851. * to allow using the following syntax to read a property or obtain event handlers:
  852. * <pre>
  853. * value=component.propertyName;
  854. * handlers=component.eventName;
  855. * </pre>
  856. * @param {String} name the property name or event name
  857. * @returns {Mixed} the property value, event handlers attached to the event, or the named behavior (since version 1.0.2)
  858. * @throws {Yii.CException} if the property or event is not defined
  859. * @see __set
  860. */
  861. Yii.CComponent.prototype.get = function (name) {
  862. var getter, i, object, nameParts = [], limit;
  863. if (name.indexOf !== undefined && name.indexOf(".") !== -1) {
  864. nameParts = name.split(".");
  865. name = nameParts.shift();
  866. }
  867. if (this[name] !== undefined) {
  868. object = this[name];
  869. if (nameParts.length > 0) {
  870. if (object instanceof Yii.CComponent) {
  871. return object.get(nameParts.join("."));
  872. }
  873. limit = nameParts.length;
  874. for (i = 0; i < limit; i++) {
  875. name = nameParts.shift();
  876. object = object[name];
  877. if (nameParts.length === 0) {
  878. return object;
  879. }
  880. if (object instanceof Yii.CComponent) {
  881. return object.get(nameParts.join("."));
  882. }
  883. }
  884. }
  885. return object;
  886. }
  887. getter='get'+php.ucfirst(name);
  888. if(php.method_exists(this,getter)) {
  889. object = this[getter]();
  890. if (nameParts.length > 0) {
  891. if (object instanceof Yii.CComponent) {
  892. return object.get(nameParts.join("."));
  893. }
  894. limit = nameParts.length;
  895. for (i = 0; i < limit; i++) {
  896. name = nameParts.shift();
  897. object = object[name];
  898. if (nameParts.length === 0) {
  899. return object;
  900. }
  901. if (object instanceof Yii.CComponent) {
  902. return object.get(nameParts.join("."));
  903. }
  904. }
  905. }
  906. return object;
  907. }
  908. else if(php.strncasecmp(name,'on',2)===0 && php.method_exists(this,name)) {
  909. // duplicating getEventHandlers() here for performance
  910. name=name.toLowerCase();
  911. if(this._e[name] === undefined) {
  912. this._e[name]=new Yii.CList();
  913. }
  914. return this._e[name];
  915. }
  916. else if(this._m !== null && this._m[name] !== undefined) {
  917. return this._m[name];
  918. }
  919. else if(this._m !== null) {
  920. for (i in this._m) {
  921. if (this._m.hasOwnProperty(i)) {
  922. object = this._m[i];
  923. try {
  924. if(object.getEnabled() && (php.property_exists(object,name) || object.canGetProperty(name))) {
  925. if (nameParts.length > 0) {
  926. return object.get(nameParts.join("."));
  927. }
  928. return object.get(name);
  929. }
  930. }
  931. catch (e) {
  932. console.log(e);
  933. }
  934. }
  935. }
  936. }
  937. console.log(this.getClassName() + " : " + name);
  938. throw new Yii.CException(Yii.t('yii','Property "{class}.{property}" is not defined.',
  939. {'{class}':this.getClassName(), '{property}':name}));
  940. };
  941. /**
  942. * Sets value of a component property.
  943. * Do not call this method. This is a PHP magic method that we override
  944. * to allow using the following syntax to set a property or attach an event handler
  945. * <pre>
  946. * this.propertyName=value;
  947. * this.eventName=callback;
  948. * </pre>
  949. * @param {String} name the property name or the event name
  950. * @param {Mixed} value the property value or callback
  951. * @throws {Yii.CException} if the property/event is not defined or the property is read only.
  952. * @see __get
  953. */
  954. Yii.CComponent.prototype.set = function (name, value) {
  955. var setter, i, object, nameParts = [];
  956. if (name.indexOf(".") !== -1) {
  957. nameParts = name.split(".");
  958. name = nameParts.pop();
  959. return (this.get(nameParts.join("."))[name] = value);
  960. }
  961. if (this[name] !== undefined) {
  962. return (this[name] = value);
  963. }
  964. setter='set'+php.ucfirst(name);
  965. if(php.method_exists(this,setter)) {
  966. return this[setter](value);
  967. }
  968. else if(php.strncasecmp(name,'on',2)===0 && php.method_exists(this,name)) {
  969. // duplicating getEventHandlers() here for performance
  970. name=name.toLowerCase();
  971. if(this._e[name] === undefined) {
  972. this._e[name]=new Yii.CList();
  973. }
  974. return this._e[name].add(value);
  975. }
  976. else if(this._m !== null) {
  977. for (i in this._m) {
  978. if (this._m.hasOwnProperty(i)) {
  979. object = this._m[i];
  980. if(object.getEnabled() && (php.property_exists(object,name) || object.canSetProperty(name))) {
  981. return (object.set(name,value));
  982. }
  983. }
  984. }
  985. }
  986. if(php.method_exists(this,'get'+php.ucfirst(name))) {
  987. throw new Yii.CException(Yii.t('yii','Property "{class}.{property}" is read only.',
  988. {'{class}':this.getClassName(), '{property}':name}));
  989. }
  990. else {
  991. throw new Yii.CException(Yii.t('yii','Property "{class}.{property}" is not defined.',
  992. {'{class}':this.getClassName(), '{property}':name}));
  993. }
  994. };
  995. /**
  996. * Checks if a property value is null.
  997. * Do not call this method. This is a PHP magic method that we override
  998. * to allow using isset() to detect if a component property is set or not.
  999. * @param {String} name the property name or the event name
  1000. * @since 1.0.1
  1001. */
  1002. Yii.CComponent.prototype.isset = function (name) {
  1003. var getter, i, object, nameParts = [], value;
  1004. if (name.indexOf(".") !== -1) {
  1005. nameParts = name.split(".");
  1006. name = nameParts.pop();
  1007. try {
  1008. value = this.get(nameParts.join("."))[name];
  1009. if (value !== undefined && value !== null) {
  1010. return true;
  1011. }
  1012. return false;
  1013. }
  1014. catch (e) {
  1015. return false;
  1016. }
  1017. }
  1018. if (this[name] !== undefined) {
  1019. return true;
  1020. }
  1021. getter='get'+php.ucfirst(name);
  1022. if(php.method_exists(this,getter)) {
  1023. return (this[getter]()!==null);
  1024. }
  1025. else if(php.strncasecmp(name,'on',2)===0 && php.method_exists(this,name))
  1026. {
  1027. name=name.toLowerCase();
  1028. return this._e !== null && this._e[name] !== undefined && this._e[name].getCount();
  1029. }
  1030. else if(this._m !== null) {
  1031. if(this._m[name] !== undefined) {
  1032. return true;
  1033. }
  1034. for (i in this._m) {
  1035. if (this._m.hasOwnProperty(i)) {
  1036. object = this._m[i];
  1037. if(object.getEnabled() && (php.property_exists(object,name) || object.canGetProperty(name))) {
  1038. return true;
  1039. }
  1040. }
  1041. }
  1042. }
  1043. return false;
  1044. };
  1045. /**
  1046. * Sets a component property to be null.
  1047. * Do not call this method. This is a PHP magic method that we override
  1048. * to allow using unset() to set a component property to be null.
  1049. * @param {String} name the property name or the event name
  1050. * @throws {Yii.CException} if the property is read only.
  1051. * @since 1.0.1
  1052. */
  1053. Yii.CComponent.prototype.unset = function (name) {
  1054. var setter, i, object, nameParts = [];
  1055. if (name.indexOf(".") !== -1) {
  1056. nameParts = name.split(".");
  1057. name = nameParts.pop();
  1058. object = this.get(nameParts.join("."))[name];
  1059. if (object.unset !== undefined) {
  1060. return object.unset(name);
  1061. }
  1062. return (this.get(nameParts.join("."))[name] = null);
  1063. }
  1064. setter='set'+php.ucfirst(name);
  1065. if (this[name] !== undefined) {
  1066. this[name] = null;
  1067. return;
  1068. }
  1069. else if(php.method_exists(this,setter)) {
  1070. this[setter](null);
  1071. }
  1072. else if(php.strncasecmp(name,'on',2)===0 && php.method_exists(this,name)) {
  1073. delete this._e[name.toLowerCase()];
  1074. }
  1075. else if(this._m !== null)
  1076. {
  1077. if(this._m[name] !== undefined) {
  1078. this.detachBehavior(name);
  1079. }
  1080. else
  1081. {
  1082. for (i in this._m) {
  1083. if (this._m.hasOwnProperty(i)) {
  1084. object = this._m[i];
  1085. if(object.getEnabled()) {
  1086. if(php.property_exists(object,name)) {
  1087. return (object[name]=null);
  1088. }
  1089. else if(object.canSetProperty(name)) {
  1090. return object[setter](null);
  1091. }
  1092. }
  1093. }
  1094. }
  1095. }
  1096. }
  1097. else if(php.method_exists(this,'get'+name)) {
  1098. throw new Yii.CException(Yii.t('yii','Property "{class}.{property}" is read only.',
  1099. {'{class}':this.getClassName(), '{property}':name}));
  1100. }
  1101. };
  1102. /**
  1103. * Calls the named method which is not a class method.
  1104. * Do not call this method. This is a PHP magic method that we override
  1105. * to implement the behavior feature.
  1106. * @param {String} name the method name
  1107. * @param {Array} parameters method parameters
  1108. * @returns {Mixed} the method return value
  1109. * @since 1.0.2
  1110. */
  1111. Yii.CComponent.prototype.call = function (name, parameters) {
  1112. var i, object;
  1113. if (this[name] !== undefined) {
  1114. return php.call_user_func_array([this,name],parameters);
  1115. }
  1116. else if(this._m!==null) {
  1117. for (i in this._m) {
  1118. if (this._m.hasOwnProperty(i)) {
  1119. object = this._m[i];
  1120. if(object.getEnabled() && php.method_exists(object,name)) {
  1121. return php.call_user_func_array([object,name],parameters);
  1122. }
  1123. }
  1124. }
  1125. }
  1126. throw new Yii.CException(Yii.t('yii','{class} does not have a method named "{name}".',
  1127. {'{class}':this.getClassName(), '{name}':name}));
  1128. };
  1129. /**
  1130. * Returns the named behavior object.
  1131. * The name 'asa' stands for 'as a'.
  1132. * @param {String} behavior the behavior name
  1133. * @returns {IBehavior} the behavior object, or null if the behavior does not exist
  1134. * @since 1.0.2
  1135. */
  1136. Yii.CComponent.prototype.asa = function (behavior) {
  1137. return this._m !== null && this._m[behavior] !== undefined ? this._m[behavior] : null;
  1138. };
  1139. /**
  1140. * Attaches a list of behaviors to the component.
  1141. * Each behavior is indexed by its name and should be an instance of
  1142. * {@link IBehavior}, a string specifying the behavior class, or an
  1143. * array of the following structure:
  1144. * <pre>
  1145. * {
  1146. * 'class':'path.to.BehaviorClass',
  1147. * 'property1':'value1',
  1148. * 'property2':'value2',
  1149. * }
  1150. * </pre>
  1151. * @param {Array} behaviors list of behaviors to be attached to the component
  1152. * @since 1.0.2
  1153. */
  1154. Yii.CComponent.prototype.attachBehaviors = function (behaviors) {
  1155. var name, behavior;
  1156. for (name in behaviors) {
  1157. if (behaviors.hasOwnProperty(name)) {
  1158. behavior = behaviors[name];
  1159. this.attachBehavior(name,behavior);
  1160. }
  1161. }
  1162. };
  1163. /**
  1164. * Detaches all behaviors from the component.
  1165. * @since 1.0.2
  1166. */
  1167. Yii.CComponent.prototype.detachBehaviors = function () {
  1168. var name, behavior;
  1169. if(this._m!==null) {
  1170. for (name in this._m) {
  1171. if (this._m.hasOwnProperty(name)) {
  1172. behavior = this._m[name];
  1173. this.detachBehavior(name);
  1174. }
  1175. }
  1176. this._m=null;
  1177. }
  1178. };
  1179. /**
  1180. * Attaches a behavior to this component.
  1181. * This method will create the behavior object based on the given
  1182. * configuration. After that, the behavior object will be initialized
  1183. * by calling its {@link IBehavior::attach} method.
  1184. * @par…

Large files files are truncated, but you can click here to view the full file