Skip to content
Browse files

removed carriage returns from files.

  • Loading branch information...
1 parent 8d4d1d3 commit 55bdd955a573a87f67589b66f1029d9b37434a16 qiang.xue committed
Showing with 4,845 additions and 4,845 deletions.
  1. +31 −31 LICENSE
  2. +62 −62 README
  3. +20 −20 UPGRADE
  4. +4 −4 build/build.xml
  5. +290 −290 build/commands/ApiCommand.php
  6. +78 −78 build/commands/AutoloadCommand.php
  7. +324 −324 build/commands/CldrCommand.php
  8. +219 −219 build/commands/LiteCommand.php
  9. +643 −643 build/commands/api/ApiModel.php
  10. +43 −43 build/commands/api/layouts/main.php
  11. +34 −34 build/commands/api/views/chmContents.php
  12. +41 −41 build/commands/api/views/chmIndex.php
  13. +22 −22 build/commands/api/views/chmProject.php
  14. +29 −29 build/commands/api/views/class.php
  15. +37 −37 build/commands/api/views/classSummary.php
  16. +26 −26 build/commands/api/views/eventDetails.php
  17. +19 −19 build/commands/api/views/eventSummary.php
  18. +18 −18 build/commands/api/views/index.php
  19. +46 −46 build/commands/api/views/methodDetails.php
  20. +21 −21 build/commands/api/views/methodSummary.php
  21. +27 −27 build/commands/api/views/propertyDetails.php
  22. +22 −22 build/commands/api/views/propertySummary.php
  23. +9 −9 build/commands/api/views/seeAlso.php
  24. +5 −5 build/commands/lite/index.php
  25. +67 −67 build/commands/lite/protected/components/MainMenu.php
  26. +26 −26 build/commands/lite/protected/components/UserIdentity.php
  27. +6 −6 build/commands/lite/protected/components/views/mainMenu.php
  28. +20 −20 build/commands/lite/protected/config/main.php
  29. +168 −168 build/commands/lite/protected/controllers/PostController.php
  30. +56 −56 build/commands/lite/protected/controllers/SiteController.php
  31. +59 −59 build/commands/lite/protected/models/LoginForm.php
  32. +56 −56 build/commands/lite/protected/models/Post.php
  33. +39 −39 build/commands/lite/protected/views/layouts/main.php
  34. +22 −22 build/commands/lite/protected/views/post/create.php
  35. +24 −24 build/commands/lite/protected/views/post/list.php
  36. +31 −31 build/commands/lite/protected/views/post/show.php
  37. +23 −23 build/commands/lite/protected/views/post/update.php
  38. +40 −40 build/commands/lite/protected/views/site/index.php
  39. +39 −39 build/commands/lite/protected/views/site/login.php
  40. +6 −6 demos/helloworld/index.php
  41. +14 −14 demos/helloworld/protected/controllers/SiteController.php
  42. +11 −11 demos/phonebook/index.php
  43. +26 −26 demos/phonebook/protected/components/Identity.php
  44. +20 −20 demos/phonebook/protected/config/main.php
  45. +142 −142 demos/phonebook/protected/controllers/SiteController.php
  46. +24 −24 demos/phonebook/protected/models/Contact.php
  47. +42 −42 demos/phonebook/protected/views/site/index.php
  48. +390 −390 framework/YiiBase.php
  49. +100 −100 framework/caching/CApcCache.php
  50. +259 −259 framework/caching/CCache.php
  51. +227 −227 framework/caching/CDbCache.php
  52. +61 −61 framework/caching/dependencies/CCacheDependency.php
  53. +68 −68 framework/caching/dependencies/CChainedCacheDependency.php
  54. +86 −86 framework/caching/dependencies/CDbCacheDependency.php
  55. +134 −134 framework/caching/dependencies/CDirectoryCacheDependency.php
  56. +53 −53 framework/caching/dependencies/CFileCacheDependency.php
  57. +54 −54 framework/caching/dependencies/CGlobalStateCacheDependency.php
  58. +191 −191 framework/cli/commands/MessageCommand.php
  59. +112 −112 framework/cli/commands/ShellCommand.php
  60. +79 −79 framework/cli/commands/WebAppCommand.php
Sorry, we could not display the entire diff because too many files (699) changed.
View
62 LICENSE
@@ -1,31 +1,31 @@
-The Yii framework is free software. It is released under the terms of
-the following BSD License.
-
-Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
- * Neither the name of Yii Software LLC nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
+The Yii framework is free software. It is released under the terms of
+the following BSD License.
+
+Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name of Yii Software LLC nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
View
124 README
@@ -1,62 +1,62 @@
-
- Yii Web Programming Framework
- =============================
-
-Thank you for choosing Yii - a high-performance programming framework
-for developing Web applications in PHP 5.
-
-
-INSTALLATION
-------------
-Please make sure the release file is unpacked under a Web-accessible
-directory. You shall see the following files and directories:
-
- demos/ containing Yii demos
- framework/ containing Yii framework source files
- requirements/ containing Yii requirement checker
- CHANGELOG describing changes in every Yii release
- LICENSE license of Yii
- README this file
- UPGRADE upgrading instructions
-
-
-REQUIREMENTS
-------------
-The minimum requirement by Yii is that your Web server supports
-PHP 5.1.0 or above. Yii has been tested with Apache HTTP server
-on Windows and Linux operating systems.
-
-Please access the following URL to check if your Web server reaches
-the requirements by Yii, assuming "YiiPath" is where Yii is installed:
-
- http://hostname/YiiPath/requirements/index.php
-
-
-QUICK START
------------
-Yii comes with a command line tool called "yiic" that can create
-a skeleton Yii application for you to start with.
-
-On command line, type in the following commands:
-
- $ cd YiiPath/framework (Linux)
- cd YiiPath\framework (Windows)
-
- $ ./yiic webapp ../testdrive (Linux)
- yiic webapp ..\testdrive (Windows)
-
-The new Yii application will be created at "YiiPath/testdrive".
-You can access it with the following URL:
-
- http://hostname/YiiPath/testdrive/index.php
-
-
-WHAT's NEXT
------------
-Please visit the project website for tutorials, class reference
-and join discussions with other Yii users.
-
-
-
-The Yii Team
-http://www.yiiframework.com
+
+ Yii Web Programming Framework
+ =============================
+
+Thank you for choosing Yii - a high-performance programming framework
+for developing Web applications in PHP 5.
+
+
+INSTALLATION
+------------
+Please make sure the release file is unpacked under a Web-accessible
+directory. You shall see the following files and directories:
+
+ demos/ containing Yii demos
+ framework/ containing Yii framework source files
+ requirements/ containing Yii requirement checker
+ CHANGELOG describing changes in every Yii release
+ LICENSE license of Yii
+ README this file
+ UPGRADE upgrading instructions
+
+
+REQUIREMENTS
+------------
+The minimum requirement by Yii is that your Web server supports
+PHP 5.1.0 or above. Yii has been tested with Apache HTTP server
+on Windows and Linux operating systems.
+
+Please access the following URL to check if your Web server reaches
+the requirements by Yii, assuming "YiiPath" is where Yii is installed:
+
+ http://hostname/YiiPath/requirements/index.php
+
+
+QUICK START
+-----------
+Yii comes with a command line tool called "yiic" that can create
+a skeleton Yii application for you to start with.
+
+On command line, type in the following commands:
+
+ $ cd YiiPath/framework (Linux)
+ cd YiiPath\framework (Windows)
+
+ $ ./yiic webapp ../testdrive (Linux)
+ yiic webapp ..\testdrive (Windows)
+
+The new Yii application will be created at "YiiPath/testdrive".
+You can access it with the following URL:
+
+ http://hostname/YiiPath/testdrive/index.php
+
+
+WHAT's NEXT
+-----------
+Please visit the project website for tutorials, class reference
+and join discussions with other Yii users.
+
+
+
+The Yii Team
+http://www.yiiframework.com
View
40 UPGRADE
@@ -1,20 +1,20 @@
-
- Upgrading Instructions for Yii Framework v1.0b
- ==============================================
-
-!!!IMPORTANT!!!
-
-The following upgrading instructions are cumulative. That is,
-if you want to upgrade from version A to version C and there is
-version B between A and C, you need to following the instructions
-for both A and B.
-
-
-Upgrading from v1.0a
---------------------
-- The getIsNewRecord and setIsNewRecord methods are removed from CActiveRecord.
- Please use CActiveRecord.isNewRecord property directly.
-- CWebUser.login is now taking an identity object as parameter.
- CWebUser.switchTo is removed. You should now implement identity class
- instead of overriding CWebUser. CWebUser.roles property is removed.
- Added CWebUser.roleProvider property.
+
+ Upgrading Instructions for Yii Framework v1.0b
+ ==============================================
+
+!!!IMPORTANT!!!
+
+The following upgrading instructions are cumulative. That is,
+if you want to upgrade from version A to version C and there is
+version B between A and C, you need to following the instructions
+for both A and B.
+
+
+Upgrading from v1.0a
+--------------------
+- The getIsNewRecord and setIsNewRecord methods are removed from CActiveRecord.
+ Please use CActiveRecord.isNewRecord property directly.
+- CWebUser.login is now taking an identity object as parameter.
+ CWebUser.switchTo is removed. You should now implement identity class
+ instead of overriding CWebUser. CWebUser.roles property is removed.
+ Added CWebUser.roleProvider property.
View
8 build/build.xml
@@ -24,9 +24,9 @@
<property name="zip" value="zip" /> <!-- zip compression -->
<property name="pkgname" value="${phing.project.name}-${yii.version}.r${yii.revision}"/>
- <property name="docname" value="${phing.project.name}-docs-${yii.version}.r${yii.revision}"/>
-
- <!-- directory definitions -->
+ <property name="docname" value="${phing.project.name}-docs-${yii.version}.r${yii.revision}"/>
+
+ <!-- directory definitions -->
<property name="build.base.dir" value="release"/>
<property name="build.dist.dir" value="${build.base.dir}/dist"/>
<property name="build.src.dir" value="${build.base.dir}/${pkgname}"/>
@@ -171,5 +171,5 @@
- snapshot : generate nightly snapshot;
</echo>
- </target>
+ </target>
</project>
View
580 build/commands/ApiCommand.php
@@ -1,291 +1,291 @@
-<?php
-/**
- * ApiCommand class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- */
-
-Yii::import('application.commands.api.ApiModel');
-
-/**
- * MessageCommand extracts messages to be translated from source files.
- * The extracted messages are saved as PHP message source files
- * under the specified directory.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package system.build
- * @since 1.0
- */
-class ApiCommand extends CConsoleCommand
-{
- const URL_PATTERN='/\{\{(.*?)\|(.*?)\}\}/s';
- public $classes;
- public $packages;
- public $pageTitle;
- public $themePath;
- public $currentClass;
-
- public function getHelp()
- {
- return <<<EOD
-USAGE
- build api <output-path> [mode]
-
-DESCRIPTION
- This command generates offline API documentation for the Yii framework.
-
-PARAMETERS
- * output-path: required, the directory where the generated documentation
- would be saved.
- * mode: optional, either 'online' or 'offline' (default). This indicates
- whether the generated documentation are for online or offline use.
-
-EOD;
- }
-
- /**
- * Execute the action.
- * @param array command line parameters specific for this command
- */
- public function run($args)
- {
- if(!isset($args[0]))
- $this->usageError('the output directory is not specified.');
- if(!is_dir($docPath=$args[0]))
- $this->usageError("the output directory {$docPath} does not exist.");
-
- $offline=true;
- if(isset($args[1]) && $args[1]==='online')
- $offline=false;
-
- $options=array(
- 'fileTypes'=>array('php'),
- 'exclude'=>array(
- '.svn',
- 'yiilite.php',
- '/cli',
- '/i18n/data',
- '/messages',
- '/vendors',
- '/views',
- '/web/js',
- '/web/widgets/views',
- ),
- );
- $this->pageTitle='Yii Framework Class Reference';
- $themePath=dirname(__FILE__).'/api';
-
- $model=$this->buildModel(YII_PATH,$options);
-
- $this->classes=$model->classes;
- $this->packages=$model->packages;
-
- if($offline)
- $this->buildOfflinePages($docPath.DIRECTORY_SEPARATOR.'api',$themePath);
- else
- {
- $this->buildOnlinePages($docPath.DIRECTORY_SEPARATOR.'api',$themePath);
- $this->buildKeywords($docPath);
- }
- }
-
- protected function buildKeywords($docPath)
- {
- $keywords=array();
- foreach($this->classes as $class)
- $keywords[]=$class->name;
- foreach($this->classes as $class)
- {
- $name=$class->name;
- foreach($class->properties as $property)
- {
- if(!$property->isInherited)
- $keywords[]=$name.'.'.$property->name;
- }
- foreach($class->methods as $method)
- {
- if(!$method->isInherited)
- $keywords[]=$name.'.'.$method->name.'()';
- }
- }
- file_put_contents($docPath.'/apiKeywords.txt',implode(',',$keywords));
- }
-
- public function render($view,$data=null,$return=false,$layout='main')
- {
- $viewFile=$this->themePath."/views/{$view}.php";
- $layoutFile=$this->themePath."/layouts/{$layout}.php";
- $content=$this->renderFile($viewFile,$data,true);
- return $this->renderFile($layoutFile,array('content'=>$content),$return);
- }
-
- public function renderPartial($view,$data=null,$return=false)
- {
- $viewFile=$this->themePath."/views/{$view}.php";
- return $this->renderFile($viewFile,$data,$return);
- }
-
- protected function buildOfflinePages($docPath,$themePath)
- {
- $this->themePath=$themePath;
- @mkdir($docPath);
- $content=$this->render('index',null,true);
- $content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOfflineLink'),$content);
- file_put_contents($docPath.'/index.html',$content);
-
- foreach($this->classes as $name=>$class)
- {
- $this->currentClass=$name;
- $this->pageTitle=$name;
- $content=$this->render('class',array('class'=>$class),true);
- $content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOfflineLink'),$content);
- file_put_contents($docPath.'/'.$name.'.html',$content);
- }
-
- CFileHelper::copyDirectory($this->themePath.'/assets',$docPath,array('exclude'=>array('.svn')));
-
- $content=$this->renderPartial('chmProject',null,true);
- file_put_contents($docPath.'/manual.hhp',$content);
-
- $content=$this->renderPartial('chmIndex',null,true);
- file_put_contents($docPath.'/manual.hhk',$content);
-
- $content=$this->renderPartial('chmContents',null,true);
- file_put_contents($docPath.'/manual.hhc',$content);
- }
-
- protected function buildOnlinePages($docPath,$themePath)
- {
- $this->themePath=$themePath;
- @mkdir($docPath);
- $content=$this->renderPartial('index',null,true);
- $content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOnlineLink'),$content);
- file_put_contents($docPath.'/index.php',$content);
-
- foreach($this->classes as $name=>$class)
- {
- $this->currentClass=$name;
- $this->pageTitle=$name;
- $content=$this->renderPartial('class',array('class'=>$class),true);
- $content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOnlineLink'),$content);
- file_put_contents($docPath.'/'.$name.'.php',$content);
- }
- }
-
- protected function buildModel($sourcePath,$options)
- {
- $files=CFileHelper::findFiles($sourcePath,$options);
- $model=new ApiModel;
- $model->build($files);
- return $model;
- }
-
- public function renderInheritance($class)
- {
- $parents=array($class->signature);
- foreach($class->parentClasses as $parent)
- {
- if(isset($this->classes[$parent]))
- $parents[]='{{'.$parent.'|'.$parent.'}}';
- else
- $parents[]=$parent;
- }
- return implode(" &raquo;\n",$parents);
- }
-
- public function renderImplements($class)
- {
- $interfaces=array();
- foreach($class->interfaces as $interface)
- {
- if(isset($this->classes[$interface]))
- $interfaces[]='{{'.$interface.'|'.$interface.'}}';
- else
- $interfaces[]=$interface;
- }
- return implode(', ',$interfaces);
- }
-
- public function renderSubclasses($class)
- {
- $subclasses=array();
- foreach($class->subclasses as $subclass)
- {
- if(isset($this->classes[$subclass]))
- $subclasses[]='{{'.$subclass.'|'.$subclass.'}}';
- else
- $subclasses[]=$subclass;
- }
- return implode(', ',$subclasses);
- }
-
- public function renderTypeUrl($type)
- {
- if(isset($this->classes[$type]) && $type!==$this->currentClass)
- return '{{'.$type.'|'.$type.'}}';
- else
- return $type;
- }
-
- public function renderSubjectUrl($type,$subject,$text=null)
- {
- if($text===null)
- $text=$subject;
- if(isset($this->classes[$type]))
- return '{{'.$type.'::'.$subject.'|'.$text.'}}';
- else
- return $text;
- }
-
- public function renderPropertySignature($property)
- {
- if(!empty($property->signature))
- return $property->signature;
- $sig='';
- if(!empty($property->getter))
- $sig=$property->getter->signature;
- if(!empty($property->setter))
- {
- if($sig!=='')
- $sig.='<br/>';
- $sig.=$property->setter->signature;
- }
- return $sig;
- }
-
- protected function fixOfflineLink($matches)
- {
- if(($pos=strpos($matches[1],'::'))!==false)
- {
- $className=substr($matches[1],0,$pos);
- $method=substr($matches[1],$pos+2);
- return "<a href=\"{$className}.html#{$method}\">{$matches[2]}</a>";
- }
- else
- return "<a href=\"{$matches[1]}.html\">{$matches[2]}</a>";
- }
-
- protected function fixOnlineLink($matches)
- {
- if(($pos=strpos($matches[1],'::'))!==false)
- {
- $className=substr($matches[1],0,$pos);
- $method=substr($matches[1],$pos+2);
- if($className==='index')
- return "<a href=\"/doc/api/#{$method}\">{$matches[2]}</a>";
- else
- return "<a href=\"/doc/api/{$className}#{$method}\">{$matches[2]}</a>";
- }
- else
- {
- if($matches[1]==='index')
- return "<a href=\"/doc/api/\">{$matches[2]}</a>";
- else
- return "<a href=\"/doc/api/{$matches[1]}\">{$matches[2]}</a>";
- }
- }
+<?php
+/**
+ * ApiCommand class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+Yii::import('application.commands.api.ApiModel');
+
+/**
+ * MessageCommand extracts messages to be translated from source files.
+ * The extracted messages are saved as PHP message source files
+ * under the specified directory.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.build
+ * @since 1.0
+ */
+class ApiCommand extends CConsoleCommand
+{
+ const URL_PATTERN='/\{\{(.*?)\|(.*?)\}\}/s';
+ public $classes;
+ public $packages;
+ public $pageTitle;
+ public $themePath;
+ public $currentClass;
+
+ public function getHelp()
+ {
+ return <<<EOD
+USAGE
+ build api <output-path> [mode]
+
+DESCRIPTION
+ This command generates offline API documentation for the Yii framework.
+
+PARAMETERS
+ * output-path: required, the directory where the generated documentation
+ would be saved.
+ * mode: optional, either 'online' or 'offline' (default). This indicates
+ whether the generated documentation are for online or offline use.
+
+EOD;
+ }
+
+ /**
+ * Execute the action.
+ * @param array command line parameters specific for this command
+ */
+ public function run($args)
+ {
+ if(!isset($args[0]))
+ $this->usageError('the output directory is not specified.');
+ if(!is_dir($docPath=$args[0]))
+ $this->usageError("the output directory {$docPath} does not exist.");
+
+ $offline=true;
+ if(isset($args[1]) && $args[1]==='online')
+ $offline=false;
+
+ $options=array(
+ 'fileTypes'=>array('php'),
+ 'exclude'=>array(
+ '.svn',
+ 'yiilite.php',
+ '/cli',
+ '/i18n/data',
+ '/messages',
+ '/vendors',
+ '/views',
+ '/web/js',
+ '/web/widgets/views',
+ ),
+ );
+ $this->pageTitle='Yii Framework Class Reference';
+ $themePath=dirname(__FILE__).'/api';
+
+ $model=$this->buildModel(YII_PATH,$options);
+
+ $this->classes=$model->classes;
+ $this->packages=$model->packages;
+
+ if($offline)
+ $this->buildOfflinePages($docPath.DIRECTORY_SEPARATOR.'api',$themePath);
+ else
+ {
+ $this->buildOnlinePages($docPath.DIRECTORY_SEPARATOR.'api',$themePath);
+ $this->buildKeywords($docPath);
+ }
+ }
+
+ protected function buildKeywords($docPath)
+ {
+ $keywords=array();
+ foreach($this->classes as $class)
+ $keywords[]=$class->name;
+ foreach($this->classes as $class)
+ {
+ $name=$class->name;
+ foreach($class->properties as $property)
+ {
+ if(!$property->isInherited)
+ $keywords[]=$name.'.'.$property->name;
+ }
+ foreach($class->methods as $method)
+ {
+ if(!$method->isInherited)
+ $keywords[]=$name.'.'.$method->name.'()';
+ }
+ }
+ file_put_contents($docPath.'/apiKeywords.txt',implode(',',$keywords));
+ }
+
+ public function render($view,$data=null,$return=false,$layout='main')
+ {
+ $viewFile=$this->themePath."/views/{$view}.php";
+ $layoutFile=$this->themePath."/layouts/{$layout}.php";
+ $content=$this->renderFile($viewFile,$data,true);
+ return $this->renderFile($layoutFile,array('content'=>$content),$return);
+ }
+
+ public function renderPartial($view,$data=null,$return=false)
+ {
+ $viewFile=$this->themePath."/views/{$view}.php";
+ return $this->renderFile($viewFile,$data,$return);
+ }
+
+ protected function buildOfflinePages($docPath,$themePath)
+ {
+ $this->themePath=$themePath;
+ @mkdir($docPath);
+ $content=$this->render('index',null,true);
+ $content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOfflineLink'),$content);
+ file_put_contents($docPath.'/index.html',$content);
+
+ foreach($this->classes as $name=>$class)
+ {
+ $this->currentClass=$name;
+ $this->pageTitle=$name;
+ $content=$this->render('class',array('class'=>$class),true);
+ $content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOfflineLink'),$content);
+ file_put_contents($docPath.'/'.$name.'.html',$content);
+ }
+
+ CFileHelper::copyDirectory($this->themePath.'/assets',$docPath,array('exclude'=>array('.svn')));
+
+ $content=$this->renderPartial('chmProject',null,true);
+ file_put_contents($docPath.'/manual.hhp',$content);
+
+ $content=$this->renderPartial('chmIndex',null,true);
+ file_put_contents($docPath.'/manual.hhk',$content);
+
+ $content=$this->renderPartial('chmContents',null,true);
+ file_put_contents($docPath.'/manual.hhc',$content);
+ }
+
+ protected function buildOnlinePages($docPath,$themePath)
+ {
+ $this->themePath=$themePath;
+ @mkdir($docPath);
+ $content=$this->renderPartial('index',null,true);
+ $content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOnlineLink'),$content);
+ file_put_contents($docPath.'/index.php',$content);
+
+ foreach($this->classes as $name=>$class)
+ {
+ $this->currentClass=$name;
+ $this->pageTitle=$name;
+ $content=$this->renderPartial('class',array('class'=>$class),true);
+ $content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOnlineLink'),$content);
+ file_put_contents($docPath.'/'.$name.'.php',$content);
+ }
+ }
+
+ protected function buildModel($sourcePath,$options)
+ {
+ $files=CFileHelper::findFiles($sourcePath,$options);
+ $model=new ApiModel;
+ $model->build($files);
+ return $model;
+ }
+
+ public function renderInheritance($class)
+ {
+ $parents=array($class->signature);
+ foreach($class->parentClasses as $parent)
+ {
+ if(isset($this->classes[$parent]))
+ $parents[]='{{'.$parent.'|'.$parent.'}}';
+ else
+ $parents[]=$parent;
+ }
+ return implode(" &raquo;\n",$parents);
+ }
+
+ public function renderImplements($class)
+ {
+ $interfaces=array();
+ foreach($class->interfaces as $interface)
+ {
+ if(isset($this->classes[$interface]))
+ $interfaces[]='{{'.$interface.'|'.$interface.'}}';
+ else
+ $interfaces[]=$interface;
+ }
+ return implode(', ',$interfaces);
+ }
+
+ public function renderSubclasses($class)
+ {
+ $subclasses=array();
+ foreach($class->subclasses as $subclass)
+ {
+ if(isset($this->classes[$subclass]))
+ $subclasses[]='{{'.$subclass.'|'.$subclass.'}}';
+ else
+ $subclasses[]=$subclass;
+ }
+ return implode(', ',$subclasses);
+ }
+
+ public function renderTypeUrl($type)
+ {
+ if(isset($this->classes[$type]) && $type!==$this->currentClass)
+ return '{{'.$type.'|'.$type.'}}';
+ else
+ return $type;
+ }
+
+ public function renderSubjectUrl($type,$subject,$text=null)
+ {
+ if($text===null)
+ $text=$subject;
+ if(isset($this->classes[$type]))
+ return '{{'.$type.'::'.$subject.'|'.$text.'}}';
+ else
+ return $text;
+ }
+
+ public function renderPropertySignature($property)
+ {
+ if(!empty($property->signature))
+ return $property->signature;
+ $sig='';
+ if(!empty($property->getter))
+ $sig=$property->getter->signature;
+ if(!empty($property->setter))
+ {
+ if($sig!=='')
+ $sig.='<br/>';
+ $sig.=$property->setter->signature;
+ }
+ return $sig;
+ }
+
+ protected function fixOfflineLink($matches)
+ {
+ if(($pos=strpos($matches[1],'::'))!==false)
+ {
+ $className=substr($matches[1],0,$pos);
+ $method=substr($matches[1],$pos+2);
+ return "<a href=\"{$className}.html#{$method}\">{$matches[2]}</a>";
+ }
+ else
+ return "<a href=\"{$matches[1]}.html\">{$matches[2]}</a>";
+ }
+
+ protected function fixOnlineLink($matches)
+ {
+ if(($pos=strpos($matches[1],'::'))!==false)
+ {
+ $className=substr($matches[1],0,$pos);
+ $method=substr($matches[1],$pos+2);
+ if($className==='index')
+ return "<a href=\"/doc/api/#{$method}\">{$matches[2]}</a>";
+ else
+ return "<a href=\"/doc/api/{$className}#{$method}\">{$matches[2]}</a>";
+ }
+ else
+ {
+ if($matches[1]==='index')
+ return "<a href=\"/doc/api/\">{$matches[2]}</a>";
+ else
+ return "<a href=\"/doc/api/{$matches[1]}\">{$matches[2]}</a>";
+ }
+ }
}
View
156 build/commands/AutoloadCommand.php
@@ -1,79 +1,79 @@
-<?php
-/**
- * AutoloadCommand class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- * @version $Id$
- */
-
-/**
- * AutoloadCommand generates the class map for {@link YiiBase}.
- * The class file YiiBase.php will be modified with updated class map.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package system.build
- * @since 1.0
- */
-class AutoloadCommand extends CConsoleCommand
-{
- public function getHelp()
- {
- return <<<EOD
-USAGE
- build autoload
-
-DESCRIPTION
- This command updates YiiBase.php with the latest class map.
- The class map is used by Yii::autoload() to quickly include a class on demand.
-
- Do not run this command unless you change or add core framework classes.
-
-EOD;
- }
-
- /**
- * Execute the action.
- * @param array command line parameters specific for this command
- */
- public function run($args)
- {
- $options=array(
- 'fileTypes'=>array('php'),
- 'exclude'=>array(
- '.svn',
- '/messages',
- '/views',
- '/cli',
- '/yii.php',
- '/web/js',
- '/vendors',
- '/i18n/data',
- ),
- );
- $files=CFileHelper::findFiles(YII_PATH,$options);
- $map='';
- foreach($files as $file)
- {
- if(($pos=strpos($file,YII_PATH))!==0)
- die("Invalid file '$file' found.");
- $path=str_replace('\\','/',substr($file,strlen(YII_PATH)));
- $className=substr(basename($path),0,-4);
- if($className[0]==='C')
- $map.="\t\t'$className' => '$path',\n";
- }
-
- $yiiBase=file_get_contents(YII_PATH.'/YiiBase.php');
- $newYiiBase=preg_replace('/private\s+static\s+\$_coreClasses\s*=\s*array\s*\([^\)]*\)\s*;/',"private static \$_coreClasses=array(\n{$map}\t);",$yiiBase);
- if($yiiBase!==$newYiiBase)
- {
- file_put_contents(YII_PATH.'/YiiBase.php',$newYiiBase);
- echo "YiiBase.php is updated successfully.\n";
- }
- else
- echo "Nothing changed.\n";
- }
+<?php
+/**
+ * AutoloadCommand class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ * @version $Id$
+ */
+
+/**
+ * AutoloadCommand generates the class map for {@link YiiBase}.
+ * The class file YiiBase.php will be modified with updated class map.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.build
+ * @since 1.0
+ */
+class AutoloadCommand extends CConsoleCommand
+{
+ public function getHelp()
+ {
+ return <<<EOD
+USAGE
+ build autoload
+
+DESCRIPTION
+ This command updates YiiBase.php with the latest class map.
+ The class map is used by Yii::autoload() to quickly include a class on demand.
+
+ Do not run this command unless you change or add core framework classes.
+
+EOD;
+ }
+
+ /**
+ * Execute the action.
+ * @param array command line parameters specific for this command
+ */
+ public function run($args)
+ {
+ $options=array(
+ 'fileTypes'=>array('php'),
+ 'exclude'=>array(
+ '.svn',
+ '/messages',
+ '/views',
+ '/cli',
+ '/yii.php',
+ '/web/js',
+ '/vendors',
+ '/i18n/data',
+ ),
+ );
+ $files=CFileHelper::findFiles(YII_PATH,$options);
+ $map='';
+ foreach($files as $file)
+ {
+ if(($pos=strpos($file,YII_PATH))!==0)
+ die("Invalid file '$file' found.");
+ $path=str_replace('\\','/',substr($file,strlen(YII_PATH)));
+ $className=substr(basename($path),0,-4);
+ if($className[0]==='C')
+ $map.="\t\t'$className' => '$path',\n";
+ }
+
+ $yiiBase=file_get_contents(YII_PATH.'/YiiBase.php');
+ $newYiiBase=preg_replace('/private\s+static\s+\$_coreClasses\s*=\s*array\s*\([^\)]*\)\s*;/',"private static \$_coreClasses=array(\n{$map}\t);",$yiiBase);
+ if($yiiBase!==$newYiiBase)
+ {
+ file_put_contents(YII_PATH.'/YiiBase.php',$newYiiBase);
+ echo "YiiBase.php is updated successfully.\n";
+ }
+ else
+ echo "Nothing changed.\n";
+ }
}
View
648 build/commands/CldrCommand.php
@@ -1,325 +1,325 @@
-<?php
-/**
- * CldrCommand class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- * @version $Id$
- */
-
-/**
- * CldrCommand converts the locale data from the {@link http://www.unicode.org/cldr/ CLDR project}
- * to PHP scripts so that they can be more easily used in PHP programming.
- *
- * The script respects locale inheritance so that the PHP data for a child locale
- * will contain all its parents' locale data if they are not specified in the child locale.
- * Therefore, to import the data for a locale, only the PHP script for that particular locale
- * needs to be included.
- *
- * Note, only the data relevant to number and date formatting are extracted.
- * Each PHP script file is named as the corresponding locale ID in lower case.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package system.build
- * @since 1.0
- */
-class CldrCommand extends CConsoleCommand
-{
- public function getHelp()
- {
- return <<<EOD
-USAGE
- build cldr <data-path>
-
-DESCRIPTION
- This command converts the locale data from the CLDR project
- to PHP scripts so that they can be more easily used in PHP programming.
-
- The script respects locale inheritance so that the PHP data for
- a child locale will contain all its parent locale data if they are
- not specified in the child locale. Therefore, to import the data
- for a locale, only the PHP script for that particular locale needs
- to be included.
-
- Note, only the data relevant to number and date formatting are extracted.
- Each PHP script file is named as the corresponding locale ID in lower case.
-
- The resulting PHP scripts are created under the same directory that
- contains the original CLDR data.
-
-PARAMETERS
- * data-path: required, the original CLDR data directory. This
- directory should contain hundreds of XML files.
-
-EOD;
- }
-
- /**
- * Execute the action.
- * @param array command line parameters specific for this command
- */
- public function run($args)
- {
- if(!isset($args[0]))
- $this->usageError('the CLDR data directory is not specified.');
- if(!is_dir($path=$args[0]))
- $this->usageError("directory '$path' does not exist.");
-
- // collect XML files to be processed
- $options=array(
- 'exclude'=>array('.svn'),
- 'fileTypes'=>array('xml'),
- 'level'=>0,
- );
- $files=CFileHelper::findFiles(realpath($path),$options);
- $sourceFiles=array();
- foreach($files as $file)
- $sourceFiles[basename($file)]=$file;
-
- // sort by file name so that inheritances can be processed properly
- ksort($sourceFiles);
-
- // process root first because it is inherited by all
- if(isset($sourceFiles['root.xml']))
- {
- $this->process($sourceFiles['root.xml']);
- unset($sourceFiles['root.xml']);
-
- foreach($sourceFiles as $sourceFile)
- $this->process($sourceFile);
- }
- else
- die('Unable to find the required root.xml under CLDR data directory.');
- }
-
- protected function process($path)
- {
- $source=basename($path);
- echo "processing $source...";
-
- $dir=dirname($path);
- $locale=substr($source,0,-4);
- $target=$locale.'.php';
-
- // retrieve parent data first
- if(($pos=strrpos($locale,'_'))!==false)
- $data=require($dir.DIRECTORY_SEPARATOR.substr($locale,0,$pos).'.php');
- else if($locale!=='root')
- $data=require($dir.DIRECTORY_SEPARATOR.'root.php');
- else
- $data=array();
-
- $xml=simplexml_load_file($path);
-
- $this->parseVersion($xml,$data);
-
- $this->parseNumberSymbols($xml,$data);
- $this->parseNumberFormats($xml,$data);
- $this->parseCurrencySymbols($xml,$data);
-
- $this->parseMonthNames($xml,$data);
- $this->parseWeekDayNames($xml,$data);
- $this->parseEraNames($xml,$data);
-
- $this->parseDateFormats($xml,$data);
- $this->parseTimeFormats($xml,$data);
- $this->parseDateTimeFormat($xml,$data);
- $this->parsePeriodNames($xml,$data);
-
- $data=var_export($data,true);
- $locale=substr(basename($path),0,-4);
- $content=<<<EOD
-/**
- * Locale data for '$locale'.
- *
- * This file is automatically generated by yiic cldr command.
- *
- * Copyright © 1991-2007 Unicode, Inc. All rights reserved.
- * Distributed under the Terms of Use in http://www.unicode.org/copyright.html.
- *
- * Copyright © 2008 Yii Software LLC (http://www.yiiframework.com/license/)
- */
-return $data;
-EOD;
-
- file_put_contents($dir.DIRECTORY_SEPARATOR.strtolower($locale).'.php',"<?php\n".$content."\n?>");
-
- echo "done.\n";
- }
-
- protected function parseVersion($xml,&$data)
- {
- preg_match('/[\d\.]+/',(string)$xml->identity->version['number'],$matches);
- $data['version']=$matches[0];
- }
-
- protected function parseNumberSymbols($xml,&$data)
- {
- foreach($xml->xpath('/ldml/numbers/symbols/*') as $symbol)
- $data['numberSymbols'][$symbol->getName()]=(string)$symbol;
- }
-
- protected function parseNumberFormats($xml,&$data)
- {
- $pattern=$xml->xpath('/ldml/numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern');
- if(isset($pattern[0]))
- $data['decimalFormat']=(string)$pattern[0];
- $pattern=$xml->xpath('/ldml/numbers/scientificFormats/scientificFormatLength/scientificFormat/pattern');
- if(isset($pattern[0]))
- $data['scientificFormat']=(string)$pattern[0];
- $pattern=$xml->xpath('/ldml/numbers/percentFormats/percentFormatLength/percentFormat/pattern');
- if(isset($pattern[0]))
- $data['percentFormat']=(string)$pattern[0];
- $pattern=$xml->xpath('/ldml/numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern');
- if(isset($pattern[0]))
- $data['currencyFormat']=(string)$pattern[0];
- }
-
- protected function parseCurrencySymbols($xml,&$data)
- {
- $currencies=$xml->xpath('/ldml/numbers/currencies/currency');
- foreach($currencies as $currency)
- {
- if((string)$currency->symbol!='')
- $data['currencySymbols'][(string)$currency['type']]=(string)$currency->symbol;
- }
- }
-
- protected function parseMonthNames($xml,&$data)
- {
- $monthTypes=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/months/monthContext[@type=\'format\']/monthWidth');
- if(is_array($monthTypes))
- {
- foreach($monthTypes as $monthType)
- {
- $names=array();
- foreach($monthType->xpath('month') as $month)
- $names[(string)$month['type']]=(string)$month;
- if($names!==array())
- $data['monthNames'][(string)$monthType['type']]=$names;
- }
- }
-
- if(!isset($data['monthNames']['abbreviated']))
- $data['monthNames']['abbreviated']=$data['monthNames']['wide'];
-
- $monthTypes=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'narrow\']');
- if(is_array($monthTypes) && isset($monthTypes[0]))
- {
- foreach($monthTypes[0]->xpath('month') as $month)
- $data['monthNames']['narrow'][(string)$month['type']]=(string)$month;
- }
- }
-
- protected function parseWeekDayNames($xml,&$data)
- {
- static $mapping=array(
- 'sun'=>0,
- 'mon'=>1,
- 'tue'=>2,
- 'wed'=>3,
- 'thu'=>4,
- 'fri'=>5,
- 'sat'=>6,
- );
- $dayTypes=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/days/dayContext[@type=\'format\']/dayWidth');
- if(is_array($dayTypes))
- {
- foreach($dayTypes as $dayType)
- {
- $names=array();
- foreach($dayType->xpath('day') as $day)
- $names[$mapping[(string)$day['type']]]=(string)$day;
- if($names!==array())
- $data['weekDayNames'][(string)$dayType['type']]=$names;
- }
- }
-
- if(!isset($data['weekDayNames']['abbreviated']))
- $data['weekDayNames']['abbreviated']=$data['weekDayNames']['wide'];
-
- $dayTypes=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'narrow\']');
- if(is_array($dayTypes) && isset($dayTypes[0]))
- {
- foreach($dayTypes[0]->xpath('day') as $day)
- $data['weekDayNames']['narrow'][(string)$day['type']]=(string)$day;
- }
- }
-
- protected function parsePeriodNames($xml,&$data)
- {
- $am=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/am');
- if(is_array($am) && isset($am[0]))
- $data['amName']=(string)$am[0];
- $pm=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/pm');
- if(is_array($pm) && isset($pm[0]))
- $data['pmName']=(string)$pm[0];
- }
-
- protected function parseEraNames($xml,&$data)
- {
- $era=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/eras/eraAbbr');
- if(is_array($era) && isset($era[0]))
- {
- foreach($era[0]->xpath('era') as $e)
- $data['eraNames']['abbreviated'][(string)$e['type']]=(string)$e;
- }
-
- $era=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/eras/eraNames');
- if(is_array($era) && isset($era[0]))
- {
- foreach($era[0]->xpath('era') as $e)
- $data['eraNames']['wide'][(string)$e['type']]=(string)$e;
- }
- else if(!isset($data['eraNames']['wide']))
- $data['eraNames']['wide']=$data['eraNames']['abbreviated'];
-
- $era=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/eras/eraNarrow');
- if(is_array($era) && isset($era[0]))
- {
- foreach($era[0]->xpath('era') as $e)
- $data['eraNames']['narrow'][(string)$e['type']]=(string)$e;
- }
- else if(!isset($data['eraNames']['narrow']))
- $data['eraNames']['narrow']=$data['eraNames']['abbreviated'];
- }
-
- protected function parseDateFormats($xml,&$data)
- {
- $types=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/dateFormats/dateFormatLength');
- if(is_array($types))
- {
- foreach($types as $type)
- {
- $pattern=$type->xpath('dateFormat/pattern');
- $data['dateFormats'][(string)$type['type']]=(string)$pattern[0];
- }
- }
- }
-
- protected function parseTimeFormats($xml,&$data)
- {
- $types=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/timeFormats/timeFormatLength');
- if(is_array($types))
- {
- foreach($types as $type)
- {
- $pattern=$type->xpath('timeFormat/pattern');
- $data['timeFormats'][(string)$type['type']]=(string)$pattern[0];
- }
- }
- }
-
- protected function parseDateTimeFormat($xml,&$data)
- {
- $types=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/dateTimeFormats/dateTimeFormatLength');
- if(is_array($types) && isset($types[0]))
- {
- $pattern=$types[0]->xpath('dateTimeFormat/pattern');
- $data['dateTimeFormat']=(string)$pattern[0];
- }
- }
+<?php
+/**
+ * CldrCommand class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ * @version $Id$
+ */
+
+/**
+ * CldrCommand converts the locale data from the {@link http://www.unicode.org/cldr/ CLDR project}
+ * to PHP scripts so that they can be more easily used in PHP programming.
+ *
+ * The script respects locale inheritance so that the PHP data for a child locale
+ * will contain all its parents' locale data if they are not specified in the child locale.
+ * Therefore, to import the data for a locale, only the PHP script for that particular locale
+ * needs to be included.
+ *
+ * Note, only the data relevant to number and date formatting are extracted.
+ * Each PHP script file is named as the corresponding locale ID in lower case.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.build
+ * @since 1.0
+ */
+class CldrCommand extends CConsoleCommand
+{
+ public function getHelp()
+ {
+ return <<<EOD
+USAGE
+ build cldr <data-path>
+
+DESCRIPTION
+ This command converts the locale data from the CLDR project
+ to PHP scripts so that they can be more easily used in PHP programming.
+
+ The script respects locale inheritance so that the PHP data for
+ a child locale will contain all its parent locale data if they are
+ not specified in the child locale. Therefore, to import the data
+ for a locale, only the PHP script for that particular locale needs
+ to be included.
+
+ Note, only the data relevant to number and date formatting are extracted.
+ Each PHP script file is named as the corresponding locale ID in lower case.
+
+ The resulting PHP scripts are created under the same directory that
+ contains the original CLDR data.
+
+PARAMETERS
+ * data-path: required, the original CLDR data directory. This
+ directory should contain hundreds of XML files.
+
+EOD;
+ }
+
+ /**
+ * Execute the action.
+ * @param array command line parameters specific for this command
+ */
+ public function run($args)
+ {
+ if(!isset($args[0]))
+ $this->usageError('the CLDR data directory is not specified.');
+ if(!is_dir($path=$args[0]))
+ $this->usageError("directory '$path' does not exist.");
+
+ // collect XML files to be processed
+ $options=array(
+ 'exclude'=>array('.svn'),
+ 'fileTypes'=>array('xml'),
+ 'level'=>0,
+ );
+ $files=CFileHelper::findFiles(realpath($path),$options);
+ $sourceFiles=array();
+ foreach($files as $file)
+ $sourceFiles[basename($file)]=$file;
+
+ // sort by file name so that inheritances can be processed properly
+ ksort($sourceFiles);
+
+ // process root first because it is inherited by all
+ if(isset($sourceFiles['root.xml']))
+ {
+ $this->process($sourceFiles['root.xml']);
+ unset($sourceFiles['root.xml']);
+
+ foreach($sourceFiles as $sourceFile)
+ $this->process($sourceFile);
+ }
+ else
+ die('Unable to find the required root.xml under CLDR data directory.');
+ }
+
+ protected function process($path)
+ {
+ $source=basename($path);
+ echo "processing $source...";
+
+ $dir=dirname($path);
+ $locale=substr($source,0,-4);
+ $target=$locale.'.php';
+
+ // retrieve parent data first
+ if(($pos=strrpos($locale,'_'))!==false)
+ $data=require($dir.DIRECTORY_SEPARATOR.substr($locale,0,$pos).'.php');
+ else if($locale!=='root')
+ $data=require($dir.DIRECTORY_SEPARATOR.'root.php');
+ else
+ $data=array();
+
+ $xml=simplexml_load_file($path);
+
+ $this->parseVersion($xml,$data);
+
+ $this->parseNumberSymbols($xml,$data);
+ $this->parseNumberFormats($xml,$data);
+ $this->parseCurrencySymbols($xml,$data);
+
+ $this->parseMonthNames($xml,$data);
+ $this->parseWeekDayNames($xml,$data);
+ $this->parseEraNames($xml,$data);
+
+ $this->parseDateFormats($xml,$data);
+ $this->parseTimeFormats($xml,$data);
+ $this->parseDateTimeFormat($xml,$data);
+ $this->parsePeriodNames($xml,$data);
+
+ $data=str_replace("\r",'',var_export($data,true));
+ $locale=substr(basename($path),0,-4);
+ $content=<<<EOD
+/**
+ * Locale data for '$locale'.
+ *
+ * This file is automatically generated by yiic cldr command.
+ *
+ * Copyright © 1991-2007 Unicode, Inc. All rights reserved.
+ * Distributed under the Terms of Use in http://www.unicode.org/copyright.html.
+ *
+ * Copyright © 2008 Yii Software LLC (http://www.yiiframework.com/license/)
+ */
+return $data;
+EOD;
+
+ file_put_contents($dir.DIRECTORY_SEPARATOR.strtolower($locale).'.php',"<?php\n".$content."\n");
+
+ echo "done.\n";
+ }
+
+ protected function parseVersion($xml,&$data)
+ {
+ preg_match('/[\d\.]+/',(string)$xml->identity->version['number'],$matches);
+ $data['version']=$matches[0];
+ }
+
+ protected function parseNumberSymbols($xml,&$data)
+ {
+ foreach($xml->xpath('/ldml/numbers/symbols/*') as $symbol)
+ $data['numberSymbols'][$symbol->getName()]=(string)$symbol;
+ }
+
+ protected function parseNumberFormats($xml,&$data)
+ {
+ $pattern=$xml->xpath('/ldml/numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern');
+ if(isset($pattern[0]))
+ $data['decimalFormat']=(string)$pattern[0];
+ $pattern=$xml->xpath('/ldml/numbers/scientificFormats/scientificFormatLength/scientificFormat/pattern');
+ if(isset($pattern[0]))
+ $data['scientificFormat']=(string)$pattern[0];
+ $pattern=$xml->xpath('/ldml/numbers/percentFormats/percentFormatLength/percentFormat/pattern');
+ if(isset($pattern[0]))
+ $data['percentFormat']=(string)$pattern[0];
+ $pattern=$xml->xpath('/ldml/numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern');
+ if(isset($pattern[0]))
+ $data['currencyFormat']=(string)$pattern[0];
+ }
+
+ protected function parseCurrencySymbols($xml,&$data)
+ {
+ $currencies=$xml->xpath('/ldml/numbers/currencies/currency');
+ foreach($currencies as $currency)
+ {
+ if((string)$currency->symbol!='')
+ $data['currencySymbols'][(string)$currency['type']]=(string)$currency->symbol;
+ }
+ }
+
+ protected function parseMonthNames($xml,&$data)
+ {
+ $monthTypes=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/months/monthContext[@type=\'format\']/monthWidth');
+ if(is_array($monthTypes))
+ {
+ foreach($monthTypes as $monthType)
+ {
+ $names=array();
+ foreach($monthType->xpath('month') as $month)
+ $names[(string)$month['type']]=(string)$month;
+ if($names!==array())
+ $data['monthNames'][(string)$monthType['type']]=$names;
+ }
+ }
+
+ if(!isset($data['monthNames']['abbreviated']))
+ $data['monthNames']['abbreviated']=$data['monthNames']['wide'];
+
+ $monthTypes=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'narrow\']');
+ if(is_array($monthTypes) && isset($monthTypes[0]))
+ {
+ foreach($monthTypes[0]->xpath('month') as $month)
+ $data['monthNames']['narrow'][(string)$month['type']]=(string)$month;
+ }
+ }
+
+ protected function parseWeekDayNames($xml,&$data)
+ {
+ static $mapping=array(
+ 'sun'=>0,
+ 'mon'=>1,
+ 'tue'=>2,
+ 'wed'=>3,
+ 'thu'=>4,
+ 'fri'=>5,
+ 'sat'=>6,
+ );
+ $dayTypes=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/days/dayContext[@type=\'format\']/dayWidth');
+ if(is_array($dayTypes))
+ {
+ foreach($dayTypes as $dayType)
+ {
+ $names=array();
+ foreach($dayType->xpath('day') as $day)
+ $names[$mapping[(string)$day['type']]]=(string)$day;
+ if($names!==array())
+ $data['weekDayNames'][(string)$dayType['type']]=$names;
+ }
+ }
+
+ if(!isset($data['weekDayNames']['abbreviated']))
+ $data['weekDayNames']['abbreviated']=$data['weekDayNames']['wide'];
+
+ $dayTypes=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'narrow\']');
+ if(is_array($dayTypes) && isset($dayTypes[0]))
+ {
+ foreach($dayTypes[0]->xpath('day') as $day)
+ $data['weekDayNames']['narrow'][(string)$day['type']]=(string)$day;
+ }
+ }
+
+ protected function parsePeriodNames($xml,&$data)
+ {
+ $am=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/am');
+ if(is_array($am) && isset($am[0]))
+ $data['amName']=(string)$am[0];
+ $pm=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/pm');
+ if(is_array($pm) && isset($pm[0]))
+ $data['pmName']=(string)$pm[0];
+ }
+
+ protected function parseEraNames($xml,&$data)
+ {
+ $era=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/eras/eraAbbr');
+ if(is_array($era) && isset($era[0]))
+ {
+ foreach($era[0]->xpath('era') as $e)
+ $data['eraNames']['abbreviated'][(string)$e['type']]=(string)$e;
+ }
+
+ $era=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/eras/eraNames');
+ if(is_array($era) && isset($era[0]))
+ {
+ foreach($era[0]->xpath('era') as $e)
+ $data['eraNames']['wide'][(string)$e['type']]=(string)$e;
+ }
+ else if(!isset($data['eraNames']['wide']))
+ $data['eraNames']['wide']=$data['eraNames']['abbreviated'];
+
+ $era=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/eras/eraNarrow');
+ if(is_array($era) && isset($era[0]))
+ {
+ foreach($era[0]->xpath('era') as $e)
+ $data['eraNames']['narrow'][(string)$e['type']]=(string)$e;
+ }
+ else if(!isset($data['eraNames']['narrow']))
+ $data['eraNames']['narrow']=$data['eraNames']['abbreviated'];
+ }
+
+ protected function parseDateFormats($xml,&$data)
+ {
+ $types=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/dateFormats/dateFormatLength');
+ if(is_array($types))
+ {
+ foreach($types as $type)
+ {
+ $pattern=$type->xpath('dateFormat/pattern');
+ $data['dateFormats'][(string)$type['type']]=(string)$pattern[0];
+ }
+ }
+ }
+
+ protected function parseTimeFormats($xml,&$data)
+ {
+ $types=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/timeFormats/timeFormatLength');
+ if(is_array($types))
+ {
+ foreach($types as $type)
+ {
+ $pattern=$type->xpath('timeFormat/pattern');
+ $data['timeFormats'][(string)$type['type']]=(string)$pattern[0];
+ }
+ }
+ }
+
+ protected function parseDateTimeFormat($xml,&$data)
+ {
+ $types=$xml->xpath('/ldml/dates/calendars/calendar[@type=\'gregorian\']/dateTimeFormats/dateTimeFormatLength');
+ if(is_array($types) && isset($types[0]))
+ {
+ $pattern=$types[0]->xpath('dateTimeFormat/pattern');
+ $data['dateTimeFormat']=(string)$pattern[0];
+ }
+ }
}
View
438 build/commands/LiteCommand.php
@@ -1,220 +1,220 @@
-<?php
-/**
- * LiteCommand class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- * @version $Id$
- */
-
-/**
- * LiteCommand generates yiilite.php by merging commonly used Yii class
- * files into a single one and removes all comments and trace statements.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package system.build
- * @since 1.0
- */
-class LiteCommand extends CConsoleCommand
-{
- public function getHelp()
- {
- return <<<EOD
-USAGE
- build lite
-
-DESCRIPTION
- This command generates yiilite.php by merging commonly used Yii class
- files into a single one and removes all comments and trace statements.
-
- You should not execute this command unless you change some framework
- file and need to update yii.php accordingly.
-
-EOD;
- }
-
- /**
- * Execute the action.
- * @param array command line parameters specific for this command
- */
- public function run($args)
- {
- $lastupdate=date('Y/m/d H:i:s');
- $comments="
-/**
- * Yii bootstrap file.
- *
- * This file is automatically generated using 'build lite' command.
- * It is the result of merging commonly used Yii class files with
- * comments and trace statements removed away.
- *
- * By using this file instead of yii.php, an Yii application may
- * improve performance due to the reduction of PHP parsing time.
- * The performance improvement is especially obvious when PHP APC extension
- * is enabled.
- *
- * DO NOT modify this file manually.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright Copyright &copy; 2008 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- * @version \$Id: \$
- * @since 1.0
- */
-
-";
-
- $content=$this->minifyYii(dirname(__FILE__).'/lite/index.php');
- $content="<?php\n".preg_replace('/^(\?>|<\?php)/mu','',$content)."\n?>";
- $content=$this->stripComments($content);
- $content=preg_replace('/^require_once.*\s*;\s*$/mu','',$content);
- $content=preg_replace('/^\s*Yii::trace.*\s*;\s*$/mu','',$content);
- $content=preg_replace('/^\s*Yii::(begin|end)Profile.*\s*;\s*$/mu','',$content);
- $content=$this->stripEmptyLines($content);
- $content=substr_replace($content,$comments,5,0);
- file_put_contents(YII_PATH.DIRECTORY_SEPARATOR.'yiilite.php',$content);
- echo "Done.\n";
- }
-
- protected function minifyYii($entryScript)
- {
- try
- {
- ob_start();
- $this->runRequest($entryScript);
- $this->runRequest($entryScript,array('r'=>'post/list'));
- ob_end_clean();
- }
- catch(CException $e)
- {
- echo $e;
- die();
- }
- $classes=array_merge(get_declared_classes(),get_declared_interfaces());
- $results=array();
- foreach($classes as $class)
- {
- $c=new ReflectionClass($class);
- if(strpos($c->getFileName(),YII_PATH)===0 && strpos($c->getFileName(),YII_PATH.DIRECTORY_SEPARATOR.'console')!==0)
- $results[$class]=$c->getFileName();
- }
- $results=$this->sortByInheritance($results);
-
- $content='';
- foreach($results as $fileName=>$class)
- $content.="\n".file_get_contents($fileName);
-
- return $content;
- }
-
- protected function sortByInheritance($classes)
- {
- $results=array();
- foreach($classes as $class=>$fileName)
- $this->processClass($class,$classes,$results);
- return $results;
- }
-
- protected function processClass($class,$classes,&$results)
- {
- $parentClass=get_parent_class($class);
- if($parentClass!==false && isset($classes[$parentClass]))
- {
- if(!isset($results[$classes[$parentClass]]))
- $this->processClass($parentClass,$classes,$results);
- }
- if(!isset($results[$classes[$class]]))
- {
- // some file may contain multiple classes
- // we only want to include when the primary one appears
- if($class[0]!=='C' || $class===substr(basename($classes[$class]),0,-4))
- $results[$classes[$class]]=$class;
- }
- }
-
- protected function runRequest($entryScript,$params=array())
- {
- restore_error_handler();
- restore_exception_handler();
- Yii::setApplication(null);
- Yii::setPathOfAlias('application',null);
- $_GET=$params;
- require($entryScript);
- }
-
- protected function stripComments($source)
- {
- $tokens = token_get_all($source);
- $output = '';
- foreach ($tokens as $token)
- {
- if (is_string($token))
- {
- // simple 1-character token
- $output .= $token;
- }
- else
- {
- // token array
- list($id, $text) = $token;
- switch ($id) {
- case T_DOC_COMMENT: // and this
- // no action on comments
- break;
- default:
- // anything else -> output "as is"
- $output .= $text;
- break;
- }
- }
- }
- return $output;
- }
-
- protected function stripEmptyLines($string)
- {
- $string = preg_replace("/[\r\n]+[\s\t]*[\r\n]+/", "\n", $string);
- $string = preg_replace("/^[\s\t]*[\r\n]+/", "", $string);
- return $string;
- }
-
- protected function unfoldFile($fileName)
- {
- static $unfoldedFiles=array();
- $pattern='^(Yii::import|require_once|include_once)\s*\(.*?[\'"]([^\*]*?)[\'"].*?\);';
- echo "adding $fileName...\n";
- $content=file_get_contents($fileName);
- while(preg_match("/$pattern/m",$content,$matches,PREG_OFFSET_CAPTURE))
- {
- $offset=$matches[0][1];
- $length=strlen($matches[0][0]);
- $type=$matches[1][0];
- $file=trim($matches[2][0],"'\"");
- if($type==='Yii::import')
- {
- // replace system with framework path and dot with directory separator
- $file=substr_replace(strtr($file,'.',DIRECTORY_SEPARATOR),YII_PATH,0,6).'.php';
- }
- else
- {
- $file=YII_PATH.$file;
- }
- if(($file=realpath($file))===false || !is_file($file))
- die('Unable to process file '.$fileName.' about '.$matches[0][0]);
- if(isset($unfoldedFiles[$file]))
- {
- $content=substr_replace($content,'',$offset,$length);
- }
- else
- {
- $unfoldedFiles[$file]=true;
- $content=substr_replace($content,$this->unfoldFile($file),$offset,$length);
- }
- }
- return $content;
- }
+<?php
+/**
+ * LiteCommand class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ * @version $Id$
+ */
+
+/**
+ * LiteCommand generates yiilite.php by merging commonly used Yii class
+ * files into a single one and removes all comments and trace statements.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package system.build
+ * @since 1.0
+ */
+class LiteCommand extends CConsoleCommand
+{
+ public function getHelp()
+ {
+ return <<<EOD
+USAGE
+ build lite
+
+DESCRIPTION
+ This command generates yiilite.php by merging commonly used Yii class
+ files into a single one and removes all comments and trace statements.
+
+ You should not execute this command unless you change some framework
+ file and need to update yii.php accordingly.
+
+EOD;
+ }
+
+ /**
+ * Execute the action.
+ * @param array command line parameters specific for this command
+ */
+ public function run($args)
+ {
+ $lastupdate=date('Y/m/d H:i:s');
+ $comments="
+/**
+ * Yii bootstrap file.
+ *
+ * This file is automatically generated using 'build lite' command.
+ * It is the result of merging commonly used Yii class files with
+ * comments and trace statements removed away.
+ *
+ * By using this file instead of yii.php, an Yii application may
+ * improve performance due to the reduction of PHP parsing time.
+ * The performance improvement is especially obvious when PHP APC extension
+ * is enabled.
+ *
+ * DO NOT modify this file manually.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ * @version \$Id: \$
+ * @since 1.0
+ */
+
+";
+
+ $content=$this->minifyYii(dirname(__FILE__).'/lite/index.php');
+ $content="<?php\n".preg_replace('/^(\?>|<\?php)/mu','',$content)."\n?>";
+ $content=$this->stripComments($content);
+ $content=preg_replace('/^require_once.*\s*;\s*$/mu','',$content);
+ $content=preg_replace('/^\s*Yii::trace.*\s*;\s*$/mu','',$content);
+ $content=preg_replace('/^\s*Yii::(begin|end)Profile.*\s*;\s*$/mu','',$content);
+ $content=$this->stripEmptyLines($content);
+ $content=substr_replace($content,$comments,5,0);
+ file_put_contents(YII_PATH.DIRECTORY_SEPARATOR.'yiilite.php',$content);
+ echo "Done.\n";
+ }
+
+ protected function minifyYii($entryScript)
+ {
+ try
+ {
+ ob_start();
+ $this->runRequest($entryScript);
+ $this->runRequest($entryScript,array('r'=>'post/list'));
+ ob_end_clean();
+ }
+ catch(CException $e)
+ {
+ echo $e;
+ die();
+ }
+ $classes=array_merge(get_declared_classes(),get_declared_interfaces());
+ $results=array();
+ foreach($classes as $class)
+ {
+ $c=new ReflectionClass($class);
+ if(strpos($c->getFileName(),YII_PATH)===0 && strpos($c->getFileName(),YII_PATH.DIRECTORY_SEPARATOR.'console')!==0)
+ $results[$class]=$c->getFileName();
+ }
+ $results=$this->sortByInheritance($results);
+
+ $content='';
+ foreach($results as $fileName=>$class)
+ $content.="\n".file_get_contents($fileName);
+
+ return $content;
+ }
+
+ protected function sortByInheritance($classes)
+ {
+ $results=array();
+ foreach($classes as $class=>$fileName)
+ $this->processClass($class,$classes,$results);
+ return $results;
+ }
+
+ protected function processClass($class,$classes,&$results)
+ {
+ $parentClass=get_parent_class($class);
+ if($parentClass!==false && isset($classes[$parentClass]))
+ {
+ if(!isset($results[$classes[$parentClass]]))
+ $this->processClass($parentClass,$classes,$results);
+ }
+ if(!isset($results[$classes[$class]]))
+ {
+ // some file may contain multiple classes
+ // we only want to include when the primary one appears
+ if($class[0]!=='C' || $class===substr(basename($classes[$class]),0,-4))
+ $results[$classes[$class]]=$class;
+ }
+ }
+
+ protected function runRequest($entryScript,$params=array())
+ {
+ restore_error_handler();
+ restore_exception_handler();
+ Yii::setApplication(null);
+ Yii::setPathOfAlias('application',null);
+ $_GET=$params;
+ require($entryScript);
+ }
+
+ protected function stripComments($source)
+ {
+ $tokens = token_get_all($source);
+ $output = '';
+ foreach ($tokens as $token)
+ {
+ if (is_string($token))
+ {
+ // simple 1-character token
+ $output .= $token;
+ }
+ else
+ {
+ // token array
+ list($id, $text) = $token;
+ switch ($id) {
+ case T_DOC_COMMENT: // and this
+ // no action on comments
+ break;
+ default:
+ // anything else -> output "as is"
+ $output .= $text;
+ break;
+ }
+ }
+ }
+ return $output;