75 changed files with 3322 additions and 406 deletions
			
			
		| @ -0,0 +1,164 @@ | ||||
| { | ||||
|     "_readme": [ | ||||
|         "This file locks the dependencies of your project to a known state", | ||||
|         "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" | ||||
|     ], | ||||
|     "hash": "05f7bcd0e99931b52415eaeb62d54daf", | ||||
|     "packages": [ | ||||
|         { | ||||
|             "name": "yiisoft/yii2", | ||||
|             "version": "dev-master", | ||||
|             "source": { | ||||
|                 "type": "git", | ||||
|                 "url": "https://github.com/yiisoft/yii2-framework.git", | ||||
|                 "reference": "2d93f20ba6044ac3f1957300c4ae85fd98ecf47d" | ||||
|             }, | ||||
|             "dist": { | ||||
|                 "type": "zip", | ||||
|                 "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/2d93f20ba6044ac3f1957300c4ae85fd98ecf47d", | ||||
|                 "reference": "2d93f20ba6044ac3f1957300c4ae85fd98ecf47d", | ||||
|                 "shasum": "" | ||||
|             }, | ||||
|             "require": { | ||||
|                 "ext-mbstring": "*", | ||||
|                 "lib-pcre": "*", | ||||
|                 "php": ">=5.3.7" | ||||
|             }, | ||||
|             "suggest": { | ||||
|                 "ezyang/htmlpurifier": "Required by HtmlPurifier.", | ||||
|                 "michelf/php-markdown": "Required by Markdown.", | ||||
|                 "smarty/smarty": "Required by SmartyViewRenderer.", | ||||
|                 "twig/twig": "Required by TwigViewRenderer." | ||||
|             }, | ||||
|             "type": "library", | ||||
|             "autoload": { | ||||
|                 "psr-0": { | ||||
|                     "yii\\": "/" | ||||
|                 } | ||||
|             }, | ||||
|             "notification-url": "https://packagist.org/downloads/", | ||||
|             "license": [ | ||||
|                 "BSD-3-Clause" | ||||
|             ], | ||||
|             "authors": [ | ||||
|                 { | ||||
|                     "name": "Qiang Xue", | ||||
|                     "email": "qiang.xue@gmail.com", | ||||
|                     "homepage": "http://www.yiiframework.com/", | ||||
|                     "role": "Founder and project lead" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Alexander Makarov", | ||||
|                     "email": "sam@rmcreative.ru", | ||||
|                     "homepage": "http://rmcreative.ru/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Maurizio Domba", | ||||
|                     "homepage": "http://mdomba.info/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Carsten Brandt", | ||||
|                     "email": "mail@cebe.cc", | ||||
|                     "homepage": "http://cebe.cc/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Wei Zhuo", | ||||
|                     "email": "weizhuo@gmail.com", | ||||
|                     "role": "Project site maintenance and development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Sebastián Thierer", | ||||
|                     "email": "sebas@artfos.com", | ||||
|                     "role": "Component development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Jeffrey Winesett", | ||||
|                     "email": "jefftulsa@gmail.com", | ||||
|                     "role": "Documentation and marketing" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Timur Ruziev", | ||||
|                     "email": "resurtm@gmail.com", | ||||
|                     "homepage": "http://resurtm.com/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Paul Klimov", | ||||
|                     "email": "klimov.paul@gmail.com", | ||||
|                     "role": "Core framework development" | ||||
|                 } | ||||
|             ], | ||||
|             "description": "Yii2 Web Programming Framework", | ||||
|             "homepage": "http://www.yiiframework.com/", | ||||
|             "keywords": [ | ||||
|                 "framework", | ||||
|                 "yii" | ||||
|             ], | ||||
|             "time": "2013-05-29 02:55:14" | ||||
|         }, | ||||
|         { | ||||
|             "name": "yiisoft/yii2-composer", | ||||
|             "version": "dev-master", | ||||
|             "source": { | ||||
|                 "type": "git", | ||||
|                 "url": "https://github.com/yiisoft/yii2-composer.git", | ||||
|                 "reference": "7ce4060faca940b836ab88de207638940a0a0568" | ||||
|             }, | ||||
|             "dist": { | ||||
|                 "type": "zip", | ||||
|                 "url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/7ce4060faca940b836ab88de207638940a0a0568", | ||||
|                 "reference": "7ce4060faca940b836ab88de207638940a0a0568", | ||||
|                 "shasum": "" | ||||
|             }, | ||||
|             "require": { | ||||
|                 "yiisoft/yii2": "*" | ||||
|             }, | ||||
|             "type": "library", | ||||
|             "autoload": { | ||||
|                 "psr-0": { | ||||
|                     "yii\\composer": "" | ||||
|                 } | ||||
|             }, | ||||
|             "notification-url": "https://packagist.org/downloads/", | ||||
|             "license": [ | ||||
|                 "BSD-3-Clause" | ||||
|             ], | ||||
|             "authors": [ | ||||
|                 { | ||||
|                     "name": "Qiang Xue", | ||||
|                     "email": "qiang.xue@gmail.com", | ||||
|                     "homepage": "http://www.yiiframework.com/", | ||||
|                     "role": "Founder and project lead" | ||||
|                 } | ||||
|             ], | ||||
|             "description": "The composer integration for the Yii framework", | ||||
|             "keywords": [ | ||||
|                 "composer", | ||||
|                 "install", | ||||
|                 "update", | ||||
|                 "yii" | ||||
|             ], | ||||
|             "time": "2013-05-23 19:12:45" | ||||
|         } | ||||
|     ], | ||||
|     "packages-dev": [ | ||||
| 
 | ||||
|     ], | ||||
|     "aliases": [ | ||||
| 
 | ||||
|     ], | ||||
|     "minimum-stability": "dev", | ||||
|     "stability-flags": { | ||||
|         "yiisoft/yii2": 20, | ||||
|         "yiisoft/yii2-composer": 20 | ||||
|     }, | ||||
|     "platform": { | ||||
|         "php": ">=5.3.0" | ||||
|     }, | ||||
|     "platform-dev": [ | ||||
| 
 | ||||
|     ] | ||||
| } | ||||
| @ -0,0 +1,164 @@ | ||||
| { | ||||
|     "_readme": [ | ||||
|         "This file locks the dependencies of your project to a known state", | ||||
|         "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" | ||||
|     ], | ||||
|     "hash": "0411dbbd774aa1c89256c77c68023940", | ||||
|     "packages": [ | ||||
|         { | ||||
|             "name": "yiisoft/yii2", | ||||
|             "version": "dev-master", | ||||
|             "source": { | ||||
|                 "type": "git", | ||||
|                 "url": "https://github.com/yiisoft/yii2-framework.git", | ||||
|                 "reference": "2d93f20ba6044ac3f1957300c4ae85fd98ecf47d" | ||||
|             }, | ||||
|             "dist": { | ||||
|                 "type": "zip", | ||||
|                 "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/2d93f20ba6044ac3f1957300c4ae85fd98ecf47d", | ||||
|                 "reference": "2d93f20ba6044ac3f1957300c4ae85fd98ecf47d", | ||||
|                 "shasum": "" | ||||
|             }, | ||||
|             "require": { | ||||
|                 "ext-mbstring": "*", | ||||
|                 "lib-pcre": "*", | ||||
|                 "php": ">=5.3.7" | ||||
|             }, | ||||
|             "suggest": { | ||||
|                 "ezyang/htmlpurifier": "Required by HtmlPurifier.", | ||||
|                 "michelf/php-markdown": "Required by Markdown.", | ||||
|                 "smarty/smarty": "Required by SmartyViewRenderer.", | ||||
|                 "twig/twig": "Required by TwigViewRenderer." | ||||
|             }, | ||||
|             "type": "library", | ||||
|             "autoload": { | ||||
|                 "psr-0": { | ||||
|                     "yii\\": "/" | ||||
|                 } | ||||
|             }, | ||||
|             "notification-url": "https://packagist.org/downloads/", | ||||
|             "license": [ | ||||
|                 "BSD-3-Clause" | ||||
|             ], | ||||
|             "authors": [ | ||||
|                 { | ||||
|                     "name": "Qiang Xue", | ||||
|                     "email": "qiang.xue@gmail.com", | ||||
|                     "homepage": "http://www.yiiframework.com/", | ||||
|                     "role": "Founder and project lead" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Alexander Makarov", | ||||
|                     "email": "sam@rmcreative.ru", | ||||
|                     "homepage": "http://rmcreative.ru/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Maurizio Domba", | ||||
|                     "homepage": "http://mdomba.info/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Carsten Brandt", | ||||
|                     "email": "mail@cebe.cc", | ||||
|                     "homepage": "http://cebe.cc/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Wei Zhuo", | ||||
|                     "email": "weizhuo@gmail.com", | ||||
|                     "role": "Project site maintenance and development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Sebastián Thierer", | ||||
|                     "email": "sebas@artfos.com", | ||||
|                     "role": "Component development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Jeffrey Winesett", | ||||
|                     "email": "jefftulsa@gmail.com", | ||||
|                     "role": "Documentation and marketing" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Timur Ruziev", | ||||
|                     "email": "resurtm@gmail.com", | ||||
|                     "homepage": "http://resurtm.com/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Paul Klimov", | ||||
|                     "email": "klimov.paul@gmail.com", | ||||
|                     "role": "Core framework development" | ||||
|                 } | ||||
|             ], | ||||
|             "description": "Yii2 Web Programming Framework", | ||||
|             "homepage": "http://www.yiiframework.com/", | ||||
|             "keywords": [ | ||||
|                 "framework", | ||||
|                 "yii" | ||||
|             ], | ||||
|             "time": "2013-05-29 02:55:14" | ||||
|         }, | ||||
|         { | ||||
|             "name": "yiisoft/yii2-composer", | ||||
|             "version": "dev-master", | ||||
|             "source": { | ||||
|                 "type": "git", | ||||
|                 "url": "https://github.com/yiisoft/yii2-composer.git", | ||||
|                 "reference": "7ce4060faca940b836ab88de207638940a0a0568" | ||||
|             }, | ||||
|             "dist": { | ||||
|                 "type": "zip", | ||||
|                 "url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/7ce4060faca940b836ab88de207638940a0a0568", | ||||
|                 "reference": "7ce4060faca940b836ab88de207638940a0a0568", | ||||
|                 "shasum": "" | ||||
|             }, | ||||
|             "require": { | ||||
|                 "yiisoft/yii2": "*" | ||||
|             }, | ||||
|             "type": "library", | ||||
|             "autoload": { | ||||
|                 "psr-0": { | ||||
|                     "yii\\composer": "" | ||||
|                 } | ||||
|             }, | ||||
|             "notification-url": "https://packagist.org/downloads/", | ||||
|             "license": [ | ||||
|                 "BSD-3-Clause" | ||||
|             ], | ||||
|             "authors": [ | ||||
|                 { | ||||
|                     "name": "Qiang Xue", | ||||
|                     "email": "qiang.xue@gmail.com", | ||||
|                     "homepage": "http://www.yiiframework.com/", | ||||
|                     "role": "Founder and project lead" | ||||
|                 } | ||||
|             ], | ||||
|             "description": "The composer integration for the Yii framework", | ||||
|             "keywords": [ | ||||
|                 "composer", | ||||
|                 "install", | ||||
|                 "update", | ||||
|                 "yii" | ||||
|             ], | ||||
|             "time": "2013-05-23 19:12:45" | ||||
|         } | ||||
|     ], | ||||
|     "packages-dev": [ | ||||
| 
 | ||||
|     ], | ||||
|     "aliases": [ | ||||
| 
 | ||||
|     ], | ||||
|     "minimum-stability": "dev", | ||||
|     "stability-flags": { | ||||
|         "yiisoft/yii2": 20, | ||||
|         "yiisoft/yii2-composer": 20 | ||||
|     }, | ||||
|     "platform": { | ||||
|         "php": ">=5.3.0" | ||||
|     }, | ||||
|     "platform-dev": [ | ||||
| 
 | ||||
|     ] | ||||
| } | ||||
| @ -0,0 +1,32 @@ | ||||
| The Yii framework is free software. It is released under the terms of | ||||
| the following BSD License. | ||||
| 
 | ||||
| Copyright © 2008-2013 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. | ||||
| @ -0,0 +1,56 @@ | ||||
| Yii 2 Benchmark Application | ||||
| =========================== | ||||
| 
 | ||||
| **NOTE** Yii 2 and the relevant applications and extensions are still under heavy | ||||
| development. We may make significant changes without prior notices. Please do not | ||||
| use them for production. Please consider using [Yii v1.1](https://github.com/yiisoft/yii) | ||||
| if you have a project to be deployed for production soon. | ||||
| 
 | ||||
| 
 | ||||
| Yii 2 Benchmark Application is an application built to demonstrate the minimal overhead | ||||
| introduced by the Yii framework. The application contains a single page which only renders | ||||
| the "hello world" string. | ||||
| 
 | ||||
| The application attempts to simulate the scenario in which you can achieve the best performance | ||||
| when using Yii. It does so by assuming that both of the main application configuration and the page | ||||
| content are cached in memory, and the application enables pretty URLs. | ||||
| 
 | ||||
| 
 | ||||
| DIRECTORY STRUCTURE | ||||
| ------------------- | ||||
| 
 | ||||
|       protected/          contains application source code | ||||
|           controllers/    contains Web controller classes | ||||
|       index.php           the entry script | ||||
| 
 | ||||
| 
 | ||||
| REQUIREMENTS | ||||
| ------------ | ||||
| 
 | ||||
| The minimum requirement by Yii is that your Web server supports PHP 5.3.?. | ||||
| 
 | ||||
| 
 | ||||
| INSTALLATION | ||||
| ------------ | ||||
| 
 | ||||
| If you do not have [Composer](http://getcomposer.org/), you may download it from | ||||
| [http://getcomposer.org/](http://getcomposer.org/) or run the following command on Linux/Unix/MacOS: | ||||
| 
 | ||||
| ~~~ | ||||
| curl -s http://getcomposer.org/installer | php | ||||
| ~~~ | ||||
| 
 | ||||
| You can then install the Bootstrap Application using the following command: | ||||
| 
 | ||||
| ~~~ | ||||
| php composer.phar create-project --stability=dev yiisoft/yii2-app-benchmark yii-benchmark | ||||
| ~~~ | ||||
| 
 | ||||
| Now you should be able to access the benchmark page using the URL | ||||
| 
 | ||||
| ~~~ | ||||
| http://localhost/yii-benchmark/index.php/site/hello | ||||
| ~~~ | ||||
| 
 | ||||
| In the above, we assume `yii-benchmark` is directly under the document root of your Web server. | ||||
| 
 | ||||
| @ -0,0 +1,23 @@ | ||||
| { | ||||
| 	"name": "yiisoft/yii2-app-benchmark", | ||||
| 	"description": "Yii 2 Benchmark Application", | ||||
| 	"keywords": ["yii", "framework", "benchmark", "application"], | ||||
| 	"homepage": "http://www.yiiframework.com/", | ||||
| 	"type": "project", | ||||
| 	"license": "BSD-3-Clause", | ||||
| 	"support": { | ||||
| 		"issues": "https://github.com/yiisoft/yii2/issues?state=open", | ||||
| 		"forum": "http://www.yiiframework.com/forum/", | ||||
| 		"wiki": "http://www.yiiframework.com/wiki/", | ||||
| 		"irc": "irc://irc.freenode.net/yii", | ||||
| 		"source": "https://github.com/yiisoft/yii2" | ||||
| 	}, | ||||
| 	"config": { | ||||
| 	  "vendor-dir": "protected/vendor" | ||||
| 	}, | ||||
| 	"minimum-stability": "dev", | ||||
| 	"require": { | ||||
| 		"php": ">=5.3.0", | ||||
| 		"yiisoft/yii2": "dev-master" | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,119 @@ | ||||
| { | ||||
|     "_readme": [ | ||||
|         "This file locks the dependencies of your project to a known state", | ||||
|         "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" | ||||
|     ], | ||||
|     "hash": "25a338a613af40ef87f2e280057f0d8c", | ||||
|     "packages": [ | ||||
|         { | ||||
|             "name": "yiisoft/yii2", | ||||
|             "version": "dev-master", | ||||
|             "source": { | ||||
|                 "type": "git", | ||||
|                 "url": "https://github.com/yiisoft/yii2-framework.git", | ||||
|                 "reference": "2d93f20ba6044ac3f1957300c4ae85fd98ecf47d" | ||||
|             }, | ||||
|             "dist": { | ||||
|                 "type": "zip", | ||||
|                 "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/2d93f20ba6044ac3f1957300c4ae85fd98ecf47d", | ||||
|                 "reference": "2d93f20ba6044ac3f1957300c4ae85fd98ecf47d", | ||||
|                 "shasum": "" | ||||
|             }, | ||||
|             "require": { | ||||
|                 "ext-mbstring": "*", | ||||
|                 "lib-pcre": "*", | ||||
|                 "php": ">=5.3.7" | ||||
|             }, | ||||
|             "suggest": { | ||||
|                 "ezyang/htmlpurifier": "Required by HtmlPurifier.", | ||||
|                 "michelf/php-markdown": "Required by Markdown.", | ||||
|                 "smarty/smarty": "Required by SmartyViewRenderer.", | ||||
|                 "twig/twig": "Required by TwigViewRenderer." | ||||
|             }, | ||||
|             "type": "library", | ||||
|             "autoload": { | ||||
|                 "psr-0": { | ||||
|                     "yii\\": "/" | ||||
|                 } | ||||
|             }, | ||||
|             "notification-url": "https://packagist.org/downloads/", | ||||
|             "license": [ | ||||
|                 "BSD-3-Clause" | ||||
|             ], | ||||
|             "authors": [ | ||||
|                 { | ||||
|                     "name": "Qiang Xue", | ||||
|                     "email": "qiang.xue@gmail.com", | ||||
|                     "homepage": "http://www.yiiframework.com/", | ||||
|                     "role": "Founder and project lead" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Alexander Makarov", | ||||
|                     "email": "sam@rmcreative.ru", | ||||
|                     "homepage": "http://rmcreative.ru/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Maurizio Domba", | ||||
|                     "homepage": "http://mdomba.info/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Carsten Brandt", | ||||
|                     "email": "mail@cebe.cc", | ||||
|                     "homepage": "http://cebe.cc/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Wei Zhuo", | ||||
|                     "email": "weizhuo@gmail.com", | ||||
|                     "role": "Project site maintenance and development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Sebastián Thierer", | ||||
|                     "email": "sebas@artfos.com", | ||||
|                     "role": "Component development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Jeffrey Winesett", | ||||
|                     "email": "jefftulsa@gmail.com", | ||||
|                     "role": "Documentation and marketing" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Timur Ruziev", | ||||
|                     "email": "resurtm@gmail.com", | ||||
|                     "homepage": "http://resurtm.com/", | ||||
|                     "role": "Core framework development" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Paul Klimov", | ||||
|                     "email": "klimov.paul@gmail.com", | ||||
|                     "role": "Core framework development" | ||||
|                 } | ||||
|             ], | ||||
|             "description": "Yii2 Web Programming Framework", | ||||
|             "homepage": "http://www.yiiframework.com/", | ||||
|             "keywords": [ | ||||
|                 "framework", | ||||
|                 "yii" | ||||
|             ], | ||||
|             "time": "2013-05-29 02:55:14" | ||||
|         } | ||||
|     ], | ||||
|     "packages-dev": [ | ||||
| 
 | ||||
|     ], | ||||
|     "aliases": [ | ||||
| 
 | ||||
|     ], | ||||
|     "minimum-stability": "dev", | ||||
|     "stability-flags": { | ||||
|         "yiisoft/yii2": 20 | ||||
|     }, | ||||
|     "platform": { | ||||
|         "php": ">=5.3.0" | ||||
|     }, | ||||
|     "platform-dev": [ | ||||
| 
 | ||||
|     ] | ||||
| } | ||||
| @ -0,0 +1,18 @@ | ||||
| <?php | ||||
| 
 | ||||
| defined('YII_DEBUG') or define('YII_DEBUG', false); | ||||
| 
 | ||||
| require(__DIR__ . '/protected/vendor/yiisoft/yii2/yii/Yii.php'); | ||||
| 
 | ||||
| $config = array( | ||||
| 	'id' => 'benchmark', | ||||
| 	'basePath' => __DIR__ . '/protected', | ||||
| 	'components' => array( | ||||
| 		'urlManager' => array( | ||||
| 			'enablePrettyUrl' => true, | ||||
| 		), | ||||
| 	) | ||||
| ); | ||||
| 
 | ||||
| $application = new yii\web\Application($config); | ||||
| $application->run(); | ||||
| @ -0,0 +1,13 @@ | ||||
| <?php | ||||
| 
 | ||||
| use yii\web\Controller; | ||||
| 
 | ||||
| class SiteController extends Controller | ||||
| { | ||||
| 	public $defaultAction = 'hello'; | ||||
| 
 | ||||
| 	public function actionHello() | ||||
| 	{ | ||||
| 		echo 'hello world'; | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,2 @@ | ||||
| * | ||||
| !.gitignore | ||||
| @ -0,0 +1,338 @@ | ||||
| /* | ||||
| 	Masked Input plugin for jQuery | ||||
| 	Copyright (c) 2007-2013 Josh Bush (digitalbush.com) | ||||
| 	Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
 | ||||
| 	Version: 1.3.1 | ||||
| */ | ||||
| (function($) { | ||||
| 	function getPasteEvent() { | ||||
|     var el = document.createElement('input'), | ||||
|         name = 'onpaste'; | ||||
|     el.setAttribute(name, ''); | ||||
|     return (typeof el[name] === 'function')?'paste':'input';             
 | ||||
| } | ||||
| 
 | ||||
| var pasteEventName = getPasteEvent() + ".mask", | ||||
| 	ua = navigator.userAgent, | ||||
| 	iPhone = /iphone/i.test(ua), | ||||
| 	android=/android/i.test(ua), | ||||
| 	caretTimeoutId; | ||||
| 
 | ||||
| $.mask = { | ||||
| 	//Predefined character definitions
 | ||||
| 	definitions: { | ||||
| 		'9': "[0-9]", | ||||
| 		'a': "[A-Za-z]", | ||||
| 		'*': "[A-Za-z0-9]" | ||||
| 	}, | ||||
| 	dataName: "rawMaskFn", | ||||
| 	placeholder: '_', | ||||
| }; | ||||
| 
 | ||||
| $.fn.extend({ | ||||
| 	//Helper Function for Caret positioning
 | ||||
| 	caret: function(begin, end) { | ||||
| 		var range; | ||||
| 
 | ||||
| 		if (this.length === 0 || this.is(":hidden")) { | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		if (typeof begin == 'number') { | ||||
| 			end = (typeof end === 'number') ? end : begin; | ||||
| 			return this.each(function() { | ||||
| 				if (this.setSelectionRange) { | ||||
| 					this.setSelectionRange(begin, end); | ||||
| 				} else if (this.createTextRange) { | ||||
| 					range = this.createTextRange(); | ||||
| 					range.collapse(true); | ||||
| 					range.moveEnd('character', end); | ||||
| 					range.moveStart('character', begin); | ||||
| 					range.select(); | ||||
| 				} | ||||
| 			}); | ||||
| 		} else { | ||||
| 			if (this[0].setSelectionRange) { | ||||
| 				begin = this[0].selectionStart; | ||||
| 				end = this[0].selectionEnd; | ||||
| 			} else if (document.selection && document.selection.createRange) { | ||||
| 				range = document.selection.createRange(); | ||||
| 				begin = 0 - range.duplicate().moveStart('character', -100000); | ||||
| 				end = begin + range.text.length; | ||||
| 			} | ||||
| 			return { begin: begin, end: end }; | ||||
| 		} | ||||
| 	}, | ||||
| 	unmask: function() { | ||||
| 		return this.trigger("unmask"); | ||||
| 	}, | ||||
| 	mask: function(mask, settings) { | ||||
| 		var input, | ||||
| 			defs, | ||||
| 			tests, | ||||
| 			partialPosition, | ||||
| 			firstNonMaskPos, | ||||
| 			len; | ||||
| 
 | ||||
| 		if (!mask && this.length > 0) { | ||||
| 			input = $(this[0]); | ||||
| 			return input.data($.mask.dataName)(); | ||||
| 		} | ||||
| 		settings = $.extend({ | ||||
| 			placeholder: $.mask.placeholder, // Load default placeholder
 | ||||
| 			completed: null | ||||
| 		}, settings); | ||||
| 
 | ||||
| 
 | ||||
| 		defs = $.mask.definitions; | ||||
| 		tests = []; | ||||
| 		partialPosition = len = mask.length; | ||||
| 		firstNonMaskPos = null; | ||||
| 
 | ||||
| 		$.each(mask.split(""), function(i, c) { | ||||
| 			if (c == '?') { | ||||
| 				len--; | ||||
| 				partialPosition = i; | ||||
| 			} else if (defs[c]) { | ||||
| 				tests.push(new RegExp(defs[c])); | ||||
| 				if (firstNonMaskPos === null) { | ||||
| 					firstNonMaskPos = tests.length - 1; | ||||
| 				} | ||||
| 			} else { | ||||
| 				tests.push(null); | ||||
| 			} | ||||
| 		}); | ||||
| 
 | ||||
| 		return this.trigger("unmask").each(function() { | ||||
| 			var input = $(this), | ||||
| 				buffer = $.map( | ||||
| 				mask.split(""), | ||||
| 				function(c, i) { | ||||
| 					if (c != '?') { | ||||
| 						return defs[c] ? settings.placeholder : c; | ||||
| 					} | ||||
| 				}), | ||||
| 				focusText = input.val(); | ||||
| 
 | ||||
| 			function seekNext(pos) { | ||||
| 				while (++pos < len && !tests[pos]); | ||||
| 				return pos; | ||||
| 			} | ||||
| 
 | ||||
| 			function seekPrev(pos) { | ||||
| 				while (--pos >= 0 && !tests[pos]); | ||||
| 				return pos; | ||||
| 			} | ||||
| 
 | ||||
| 			function shiftL(begin,end) { | ||||
| 				var i, | ||||
| 					j; | ||||
| 
 | ||||
| 				if (begin<0) { | ||||
| 					return; | ||||
| 				} | ||||
| 
 | ||||
| 				for (i = begin, j = seekNext(end); i < len; i++) { | ||||
| 					if (tests[i]) { | ||||
| 						if (j < len && tests[i].test(buffer[j])) { | ||||
| 							buffer[i] = buffer[j]; | ||||
| 							buffer[j] = settings.placeholder; | ||||
| 						} else { | ||||
| 							break; | ||||
| 						} | ||||
| 
 | ||||
| 						j = seekNext(j); | ||||
| 					} | ||||
| 				} | ||||
| 				writeBuffer(); | ||||
| 				input.caret(Math.max(firstNonMaskPos, begin)); | ||||
| 			} | ||||
| 
 | ||||
| 			function shiftR(pos) { | ||||
| 				var i, | ||||
| 					c, | ||||
| 					j, | ||||
| 					t; | ||||
| 
 | ||||
| 				for (i = pos, c = settings.placeholder; i < len; i++) { | ||||
| 					if (tests[i]) { | ||||
| 						j = seekNext(i); | ||||
| 						t = buffer[i]; | ||||
| 						buffer[i] = c; | ||||
| 						if (j < len && tests[j].test(t)) { | ||||
| 							c = t; | ||||
| 						} else { | ||||
| 							break; | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			function keydownEvent(e) { | ||||
| 				var k = e.which, | ||||
| 					pos, | ||||
| 					begin, | ||||
| 					end; | ||||
| 
 | ||||
| 				//backspace, delete, and escape get special treatment
 | ||||
| 				if (k === 8 || k === 46 || (iPhone && k === 127)) { | ||||
| 					pos = input.caret(); | ||||
| 					begin = pos.begin; | ||||
| 					end = pos.end; | ||||
| 
 | ||||
| 					if (end - begin === 0) { | ||||
| 						begin=k!==46?seekPrev(begin):(end=seekNext(begin-1)); | ||||
| 						end=k===46?seekNext(end):end; | ||||
| 					} | ||||
| 					clearBuffer(begin, end); | ||||
| 					shiftL(begin, end - 1); | ||||
| 
 | ||||
| 					e.preventDefault(); | ||||
| 				} else if (k == 27) {//escape
 | ||||
| 					input.val(focusText); | ||||
| 					input.caret(0, checkVal()); | ||||
| 					e.preventDefault(); | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			function keypressEvent(e) { | ||||
| 				var k = e.which, | ||||
| 					pos = input.caret(), | ||||
| 					p, | ||||
| 					c, | ||||
| 					next; | ||||
| 
 | ||||
| 				if (e.ctrlKey || e.altKey || e.metaKey || k < 32) {//Ignore
 | ||||
| 					return; | ||||
| 				} else if (k) { | ||||
| 					if (pos.end - pos.begin !== 0){ | ||||
| 						clearBuffer(pos.begin, pos.end); | ||||
| 						shiftL(pos.begin, pos.end-1); | ||||
| 					} | ||||
| 
 | ||||
| 					p = seekNext(pos.begin - 1); | ||||
| 					if (p < len) { | ||||
| 						c = String.fromCharCode(k); | ||||
| 						if (tests[p].test(c)) { | ||||
| 							shiftR(p); | ||||
| 
 | ||||
| 							buffer[p] = c; | ||||
| 							writeBuffer(); | ||||
| 							next = seekNext(p); | ||||
| 
 | ||||
| 							if(android){ | ||||
| 								setTimeout($.proxy($.fn.caret,input,next),0); | ||||
| 							}else{ | ||||
| 								input.caret(next); | ||||
| 							} | ||||
| 
 | ||||
| 							if (settings.completed && next >= len) { | ||||
| 								settings.completed.call(input); | ||||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 					e.preventDefault(); | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			function clearBuffer(start, end) { | ||||
| 				var i; | ||||
| 				for (i = start; i < end && i < len; i++) { | ||||
| 					if (tests[i]) { | ||||
| 						buffer[i] = settings.placeholder; | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			function writeBuffer() { input.val(buffer.join('')); } | ||||
| 
 | ||||
| 			function checkVal(allow) { | ||||
| 				//try to place characters where they belong
 | ||||
| 				var test = input.val(), | ||||
| 					lastMatch = -1, | ||||
| 					i, | ||||
| 					c; | ||||
| 
 | ||||
| 				for (i = 0, pos = 0; i < len; i++) { | ||||
| 					if (tests[i]) { | ||||
| 						buffer[i] = settings.placeholder; | ||||
| 						while (pos++ < test.length) { | ||||
| 							c = test.charAt(pos - 1); | ||||
| 							if (tests[i].test(c)) { | ||||
| 								buffer[i] = c; | ||||
| 								lastMatch = i; | ||||
| 								break; | ||||
| 							} | ||||
| 						} | ||||
| 						if (pos > test.length) { | ||||
| 							break; | ||||
| 						} | ||||
| 					} else if (buffer[i] === test.charAt(pos) && i !== partialPosition) { | ||||
| 						pos++; | ||||
| 						lastMatch = i; | ||||
| 					} | ||||
| 				} | ||||
| 				if (allow) { | ||||
| 					writeBuffer(); | ||||
| 				} else if (lastMatch + 1 < partialPosition) { | ||||
| 					input.val(""); | ||||
| 					clearBuffer(0, len); | ||||
| 				} else { | ||||
| 					writeBuffer(); | ||||
| 					input.val(input.val().substring(0, lastMatch + 1)); | ||||
| 				} | ||||
| 				return (partialPosition ? i : firstNonMaskPos); | ||||
| 			} | ||||
| 
 | ||||
| 			input.data($.mask.dataName,function(){ | ||||
| 				return $.map(buffer, function(c, i) { | ||||
| 					return tests[i]&&c!=settings.placeholder ? c : null; | ||||
| 				}).join(''); | ||||
| 			}); | ||||
| 
 | ||||
| 			if (!input.attr("readonly")) | ||||
| 				input | ||||
| 				.one("unmask", function() { | ||||
| 					input | ||||
| 						.unbind(".mask") | ||||
| 						.removeData($.mask.dataName); | ||||
| 				}) | ||||
| 				.bind("focus.mask", function() { | ||||
| 					clearTimeout(caretTimeoutId); | ||||
| 					var pos, | ||||
| 						moveCaret; | ||||
| 
 | ||||
| 					focusText = input.val(); | ||||
| 					pos = checkVal(); | ||||
| 					
 | ||||
| 					caretTimeoutId = setTimeout(function(){ | ||||
| 						writeBuffer(); | ||||
| 						if (pos == mask.length) { | ||||
| 							input.caret(0, pos); | ||||
| 						} else { | ||||
| 							input.caret(pos); | ||||
| 						} | ||||
| 					}, 10); | ||||
| 				}) | ||||
| 				.bind("blur.mask", function() { | ||||
| 					checkVal(); | ||||
| 					if (input.val() != focusText) | ||||
| 						input.change(); | ||||
| 				}) | ||||
| 				.bind("keydown.mask", keydownEvent) | ||||
| 				.bind("keypress.mask", keypressEvent) | ||||
| 				.bind(pasteEventName, function() { | ||||
| 					setTimeout(function() { 
 | ||||
| 						var pos=checkVal(true); | ||||
| 						input.caret(pos); 
 | ||||
| 						if (settings.completed && pos == input.val().length) | ||||
| 							settings.completed.call(input); | ||||
| 					}, 0); | ||||
| 				}); | ||||
| 			checkVal(); //Perform initial check for existing values
 | ||||
| 		}); | ||||
| 	} | ||||
| }); | ||||
| 
 | ||||
| 
 | ||||
| })(jQuery); | ||||
| @ -0,0 +1,292 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\base; | ||||
| 
 | ||||
| use Yii; | ||||
| use DateTime; | ||||
| use yii\helpers\HtmlPurifier; | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Formatter provides a set of commonly used data formatting methods. | ||||
|  * | ||||
|  * The formatting methods provided by Formatter are all named in the form of `asXyz()`. | ||||
|  * The behavior of some of them may be configured via the properties of Formatter. For example, | ||||
|  * by configuring [[dateFormat]], one may control how [[asDate()]] formats the value into a date string. | ||||
|  * | ||||
|  * @author Qiang Xue <qiang.xue@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Formatter extends Component | ||||
| { | ||||
| 	/** | ||||
| 	 * @var string the default format string to be used to format a date using PHP date() function. | ||||
| 	 */ | ||||
| 	public $dateFormat = 'Y/m/d'; | ||||
| 	/** | ||||
| 	 * @var string the default format string to be used to format a time using PHP date() function. | ||||
| 	 */ | ||||
| 	public $timeFormat = 'h:i:s A'; | ||||
| 	/** | ||||
| 	 * @var string the default format string to be used to format a date and time using PHP date() function. | ||||
| 	 */ | ||||
| 	public $datetimeFormat = 'Y/m/d h:i:s A'; | ||||
| 	/** | ||||
| 	 * @var array the text to be displayed when formatting a boolean value. The first element corresponds | ||||
| 	 * to the text display for false, the second element for true. Defaults to <code>array('No', 'Yes')</code>. | ||||
| 	 */ | ||||
| 	public $booleanFormat; | ||||
| 	/** | ||||
| 	 * @var string the character displayed as the decimal point when formatting a number. | ||||
| 	 */ | ||||
| 	public $decimalSeparator = '.'; | ||||
| 	/** | ||||
| 	 * @var string the character displayed as the thousands separator character when formatting a number. | ||||
| 	 */ | ||||
| 	public $thousandSeparator = ','; | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Initializes the component. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		if (empty($this->booleanFormat)) { | ||||
| 			$this->booleanFormat = array(Yii::t('yii', 'No'), Yii::t('yii', 'Yes')); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as is without any formatting. | ||||
| 	 * This method simply returns back the parameter without any format. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatted result | ||||
| 	 */ | ||||
| 	public function asRaw($value) | ||||
| 	{ | ||||
| 		return $value; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as an HTML-encoded plain text. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatted result | ||||
| 	 */ | ||||
| 	public function asText($value) | ||||
| 	{ | ||||
| 		return Html::encode($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as an HTML-encoded plain text with newlines converted into breaks. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatted result | ||||
| 	 */ | ||||
| 	public function asNtext($value) | ||||
| 	{ | ||||
| 		return nl2br(Html::encode($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as HTML-encoded text paragraphs. | ||||
| 	 * Each text paragraph is enclosed within a `<p>` tag. | ||||
| 	 * One or multiple consecutive empty lines divide two paragraphs. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatted result | ||||
| 	 */ | ||||
| 	public function asParagraphs($value) | ||||
| 	{ | ||||
| 		return str_replace('<p></p>', '', | ||||
| 			'<p>' . preg_replace('/[\r\n]{2,}/', "</p>\n<p>", Html::encode($value)) . '</p>' | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as HTML text. | ||||
| 	 * The value will be purified using [[HtmlPurifier]] to avoid XSS attacks. | ||||
| 	 * Use [[asRaw()]] if you do not want any purification of the value. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @param array|null $config the configuration for the HTMLPurifier class. | ||||
| 	 * @return string the formatted result | ||||
| 	 */ | ||||
| 	public function asHtml($value, $config = null) | ||||
| 	{ | ||||
| 		return HtmlPurifier::process($value, $config); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a mailto link. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatted result | ||||
| 	 */ | ||||
| 	public function asEmail($value) | ||||
| 	{ | ||||
| 		return Html::mailto($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as an image tag. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatted result | ||||
| 	 */ | ||||
| 	public function asImage($value) | ||||
| 	{ | ||||
| 		return Html::img($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a hyperlink. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatted result | ||||
| 	 */ | ||||
| 	public function asUrl($value) | ||||
| 	{ | ||||
| 		$url = $value; | ||||
| 		if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { | ||||
| 			$url = 'http://' . $url; | ||||
| 		} | ||||
| 		return Html::a(Html::encode($value), $url); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a boolean. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatted result | ||||
| 	 * @see booleanFormat | ||||
| 	 */ | ||||
| 	public function asBoolean($value) | ||||
| 	{ | ||||
| 		return $value ? $this->booleanFormat[1] : $this->booleanFormat[0]; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a date. | ||||
| 	 * @param integer|string|DateTime $value the value to be formatted. The following | ||||
| 	 * types of value are supported: | ||||
| 	 * | ||||
| 	 * - an integer representing a UNIX timestamp | ||||
| 	 * - a string that can be parsed into a UNIX timestamp via `strtotime()` | ||||
| 	 * - a PHP DateTime object | ||||
| 	 * | ||||
| 	 * @param string $format the format used to convert the value into a date string. | ||||
| 	 * If null, [[dateFormat]] will be used. The format string should be one | ||||
| 	 * that can be recognized by the PHP `date()` function. | ||||
| 	 * @return string the formatted result | ||||
| 	 * @see dateFormat | ||||
| 	 */ | ||||
| 	public function asDate($value, $format = null) | ||||
| 	{ | ||||
| 		$value = $this->normalizeDatetimeValue($value); | ||||
| 		return date($format === null ? $this->dateFormat : $format, $value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a time. | ||||
| 	 * @param integer|string|DateTime $value the value to be formatted. The following | ||||
| 	 * types of value are supported: | ||||
| 	 * | ||||
| 	 * - an integer representing a UNIX timestamp | ||||
| 	 * - a string that can be parsed into a UNIX timestamp via `strtotime()` | ||||
| 	 * - a PHP DateTime object | ||||
| 	 * | ||||
| 	 * @param string $format the format used to convert the value into a date string. | ||||
| 	 * If null, [[timeFormat]] will be used. The format string should be one | ||||
| 	 * that can be recognized by the PHP `date()` function. | ||||
| 	 * @return string the formatted result | ||||
| 	 * @see timeFormat | ||||
| 	 */ | ||||
| 	public function asTime($value, $format = null) | ||||
| 	{ | ||||
| 		$value = $this->normalizeDatetimeValue($value); | ||||
| 		return date($format === null ? $this->timeFormat : $format, $value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a datetime. | ||||
| 	 * @param integer|string|DateTime $value the value to be formatted. The following | ||||
| 	 * types of value are supported: | ||||
| 	 * | ||||
| 	 * - an integer representing a UNIX timestamp | ||||
| 	 * - a string that can be parsed into a UNIX timestamp via `strtotime()` | ||||
| 	 * - a PHP DateTime object | ||||
| 	 * | ||||
| 	 * @param string $format the format used to convert the value into a date string. | ||||
| 	 * If null, [[datetimeFormat]] will be used. The format string should be one | ||||
| 	 * that can be recognized by the PHP `date()` function. | ||||
| 	 * @return string the formatted result | ||||
| 	 * @see datetimeFormat | ||||
| 	 */ | ||||
| 	public function asDatetime($value, $format = null) | ||||
| 	{ | ||||
| 		$value = $this->normalizeDatetimeValue($value); | ||||
| 		return date($format === null ? $this->datetimeFormat : $format, $value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Normalizes the given datetime value as one that can be taken by various date/time formatting methods. | ||||
| 	 * @param mixed $value the datetime value to be normalized. | ||||
| 	 * @return mixed the normalized datetime value | ||||
| 	 */ | ||||
| 	protected function normalizeDatetimeValue($value) | ||||
| 	{ | ||||
| 		if (is_string($value)) { | ||||
| 			if (ctype_digit($value) || $value[0] === '-' && ctype_digit(substr($value, 1))) { | ||||
| 				return (int)$value; | ||||
| 			} else { | ||||
| 				return strtotime($value); | ||||
| 			} | ||||
| 		} elseif ($value instanceof DateTime) { | ||||
| 			return $value->getTimestamp(); | ||||
| 		} else { | ||||
| 			return (int)$value; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as an integer. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @return string the formatting result. | ||||
| 	 */ | ||||
| 	public function asInteger($value) | ||||
| 	{ | ||||
| 		if (is_string($value) && preg_match('/^(-?\d+)/', $value, $matches)) { | ||||
| 			return $matches[1]; | ||||
| 		} else { | ||||
| 			$value = (int)$value; | ||||
| 			return "$value"; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a double number. | ||||
| 	 * Property [[decimalSeparator]] will be used to represent the decimal point. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @param integer $decimals the number of digits after the decimal point | ||||
| 	 * @return string the formatting result. | ||||
| 	 * @see decimalSeparator | ||||
| 	 */ | ||||
| 	public function asDouble($value, $decimals = 2) | ||||
| 	{ | ||||
| 		return str_replace('.', $this->decimalSeparator, sprintf("%.{$decimals}f", $value)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a number with decimal and thousand separators. | ||||
| 	 * This method calls the PHP number_format() function to do the formatting. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @param integer $decimals the number of digits after the decimal point | ||||
| 	 * @return string the formatted result | ||||
| 	 * @see decimalSeparator | ||||
| 	 * @see thousandSeparator | ||||
| 	 */ | ||||
| 	public function asNumber($value, $decimals = 0) | ||||
| 	{ | ||||
| 		return number_format($value, $decimals, $this->decimalSeparator, $this->thousandSeparator); | ||||
| 	} | ||||
| } | ||||
| @ -1,26 +0,0 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\base; | ||||
| 
 | ||||
| /** | ||||
|  * InvalidRequestException represents an exception caused by incorrect end user request. | ||||
|  * | ||||
|  * @author Qiang Xue <qiang.xue@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class InvalidRequestException extends UserException | ||||
| { | ||||
| 	/** | ||||
| 	 * @return string the user-friendly name of this exception | ||||
| 	 */ | ||||
| 	public function getName() | ||||
| 	{ | ||||
| 		return \Yii::t('yii', 'Invalid Request'); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| @ -0,0 +1,138 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\bootstrap; | ||||
| 
 | ||||
| use yii\base\InvalidConfigException; | ||||
| use yii\helpers\ArrayHelper; | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * Nav renders a nav HTML component. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * echo Nav::widget(array( | ||||
|  *     'items' => array( | ||||
|  *         array( | ||||
|  *             'label' => 'Home', | ||||
|  *             'url' => '/', | ||||
|  *             'linkOptions' => array(...), | ||||
|  *             'active' => true, | ||||
|  *         ), | ||||
|  *         array( | ||||
|  *             'label' => 'Dropdown', | ||||
|  *             'items' => array( | ||||
|  *                  array( | ||||
|  *                      'label' => 'DropdownA', | ||||
|  *                      'url' => '#', | ||||
|  *                  ), | ||||
|  *                  array( | ||||
|  *                      'label' => 'DropdownB', | ||||
|  *                      'url' => '#', | ||||
|  *                  ), | ||||
|  *             ), | ||||
|  *         ), | ||||
|  *     ), | ||||
|  * )); | ||||
|  * ``` | ||||
|  * | ||||
|  * @see http://twitter.github.io/bootstrap/components.html#nav | ||||
|  * @author Antonio Ramirez <amigo.cobos@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Nav extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * @var array list of items in the nav widget. Each array element represents a single | ||||
| 	 * menu item with the following structure: | ||||
| 	 * | ||||
| 	 * - label: string, required, the nav item label. | ||||
| 	 * - url: optional, the item's URL. Defaults to "#". | ||||
| 	 * - linkOptions: array, optional, the HTML attributes of the item's link. | ||||
| 	 * - options: array, optional, the HTML attributes of the item container (LI). | ||||
| 	 * - active: boolean, optional, whether the item should be on active state or not. | ||||
| 	 * - dropdown: array|string, optional, the configuration array for creating a [[Dropdown]] widget, | ||||
| 	 *   or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus. | ||||
| 	 */ | ||||
| 	public $items = array(); | ||||
| 	/** | ||||
| 	 * @var boolean whether the nav items labels should be HTML-encoded. | ||||
| 	 */ | ||||
| 	public $encodeLabels = true; | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 		$this->addCssClass($this->options, 'nav'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		echo $this->renderItems(); | ||||
| 		$this->getView()->registerAssetBundle('yii/bootstrap'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders widget items. | ||||
| 	 */ | ||||
| 	public function renderItems() | ||||
| 	{ | ||||
| 		$items = array(); | ||||
| 		foreach ($this->items as $item) { | ||||
| 			$items[] = $this->renderItem($item); | ||||
| 		} | ||||
| 
 | ||||
| 		return Html::tag('ul', implode("\n", $items), $this->options); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders a widget's item. | ||||
| 	 * @param mixed $item the item to render. | ||||
| 	 * @return string the rendering result. | ||||
| 	 * @throws InvalidConfigException | ||||
| 	 */ | ||||
| 	public function renderItem($item) | ||||
| 	{ | ||||
| 		if (is_string($item)) { | ||||
| 			return $item; | ||||
| 		} | ||||
| 		if (!isset($item['label'])) { | ||||
| 			throw new InvalidConfigException("The 'label' option is required."); | ||||
| 		} | ||||
| 		$label = $this->encodeLabels ? Html::encode($item['label']) : $item['label']; | ||||
| 		$options = ArrayHelper::getValue($item, 'options', array()); | ||||
| 		$dropdown = ArrayHelper::getValue($item, 'dropdown'); | ||||
| 		$url = Html::url(ArrayHelper::getValue($item, 'url', '#')); | ||||
| 		$linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); | ||||
| 
 | ||||
| 		if(ArrayHelper::getValue($item, 'active')) { | ||||
| 			$this->addCssClass($options, 'active'); | ||||
| 		} | ||||
| 
 | ||||
| 		if ($dropdown !== null) { | ||||
| 			$linkOptions['data-toggle'] = 'dropdown'; | ||||
| 			$this->addCssClass($options, 'dropdown'); | ||||
| 			$this->addCssClass($urlOptions, 'dropdown-toggle'); | ||||
| 			$label .= ' ' . Html::tag('b', '', array('class' => 'caret')); | ||||
| 			if (is_array($dropdown)) { | ||||
| 				$dropdown['clientOptions'] = false; | ||||
| 				$dropdown = Dropdown::widget($dropdown); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return Html::tag('li', Html::a($label, $url, $linkOptions) . $dropdown, $options); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,188 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\bootstrap; | ||||
| 
 | ||||
| use yii\base\InvalidConfigException; | ||||
| use yii\helpers\ArrayHelper; | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * NavBar renders a navbar HTML component. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * echo NavBar::widget(array( | ||||
|  *     'brandLabel' => 'NavBar Test', | ||||
|  *     'items' => array( | ||||
|  *         // a Nav widget | ||||
|  *         array( | ||||
|  *             // defaults to Nav anyway. | ||||
|  *             'class' => 'yii\bootstrap\Nav', | ||||
|  *             // widget configuration | ||||
|  *             'options' => array( | ||||
|  *                 'items' => array( | ||||
|  *                     array( | ||||
|  *                         'label' => 'Home', | ||||
|  *                         'url' => '/', | ||||
|  *                         'options' => array('class' => 'active'), | ||||
|  *                     ), | ||||
|  *                     array( | ||||
|  *                         'label' => 'Dropdown', | ||||
|  *                         'content' => new Dropdown(array( | ||||
|  *                             'items' => array( | ||||
|  *                                 array( | ||||
|  *                                     'label' => 'DropdownA', | ||||
|  *                                     'url' => '#', | ||||
|  *                                 ), | ||||
|  *                                 array( | ||||
|  *                                     'label' => 'DropdownB', | ||||
|  *                                     'url' => '#' | ||||
|  *                                 ), | ||||
|  *                             ) | ||||
|  *                         ), | ||||
|  *                     ), | ||||
|  *                 ) | ||||
|  *             ), | ||||
|  *         ), | ||||
|  *         // you can also use strings | ||||
|  *         '<form class="navbar-search pull-left" action="">' . | ||||
|  *         '<input type="text" class="search-query" placeholder="Search">' . | ||||
|  *         '</form>', | ||||
|  *     ), | ||||
|  * )); | ||||
|  * ``` | ||||
|  * | ||||
|  * @see http://twitter.github.io/bootstrap/components.html#navbar | ||||
|  * @author Antonio Ramirez <amigo.cobos@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class NavBar extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * @var string the text of the brand. | ||||
| 	 * @see http://twitter.github.io/bootstrap/components.html#navbar | ||||
| 	 */ | ||||
| 	public $brandLabel; | ||||
| 	/** | ||||
| 	 * @param array|string $url the URL for the brand's hyperlink tag. This parameter will be processed by [[Html::url()]] | ||||
| 	 * and will be used for the "href" attribute of the brand link. Defaults to site root. | ||||
| 	 */ | ||||
| 	public $brandUrl = '/'; | ||||
| 	/** | ||||
| 	 * @var array the HTML attributes of the brand link. | ||||
| 	 */ | ||||
| 	public $brandOptions = array(); | ||||
| 	/** | ||||
| 	 * @var array list of menu items in the navbar widget. Each array element represents a single | ||||
| 	 * menu item with the following structure: | ||||
| 	 * | ||||
| 	 * ```php | ||||
| 	 * array( | ||||
| 	 *     // optional, the menu item class type of the widget to render. Defaults to "Nav" widget. | ||||
| 	 *     'class' => 'Menu item class type', | ||||
| 	 *     // required, the configuration options of the widget. | ||||
| 	 *     'options'=> array(...), | ||||
| 	 * ), | ||||
| 	 * // optionally, you can pass a string | ||||
| 	 * '<form class="navbar-search pull-left" action="">' . | ||||
| 	 * '<input type="text" class="search-query span2" placeholder="Search">' . | ||||
| 	 * '</form>', | ||||
| 	 * ``` | ||||
| 	 * | ||||
| 	 * Optionally, you can also use a plain string instead of an array element. | ||||
| 	 */ | ||||
| 	public $items = array(); | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 		$this->clientOptions = false; | ||||
| 		$this->addCssClass($this->options, 'navbar'); | ||||
| 		$this->addCssClass($this->brandOptions, 'brand'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		echo Html::beginTag('div', $this->options); | ||||
| 		echo $this->renderItems(); | ||||
| 		echo Html::endTag('div'); | ||||
| 		$this->getView()->registerAssetBundle(self::$responsive ? 'yii/bootstrap/responsive' : 'yii/bootstrap'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the items. | ||||
| 	 * @return string the rendering items. | ||||
| 	 */ | ||||
| 	protected function renderItems() | ||||
| 	{ | ||||
| 		$items = array(); | ||||
| 		foreach ($this->items as $item) { | ||||
| 			$items[] = $this->renderItem($item); | ||||
| 		} | ||||
| 		$contents = implode("\n", $items); | ||||
| 		$brand = Html::a($this->brandLabel, $this->brandUrl, $this->brandOptions); | ||||
| 
 | ||||
| 		if (self::$responsive) { | ||||
| 			$this->getView()->registerAssetBundle('yii/bootstrap/collapse'); | ||||
| 			$contents = Html::tag('div', | ||||
| 					$this->renderToggleButton() . | ||||
| 					$brand . "\n" . | ||||
| 					Html::tag('div', $contents, array('class' => 'nav-collapse collapse navbar-collapse')), | ||||
| 					array('class' => 'container')); | ||||
| 		} else { | ||||
| 			$contents = $brand . "\n" . $contents; | ||||
| 		} | ||||
| 
 | ||||
| 		return Html::tag('div', $contents, array('class' => 'navbar-inner')); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders a item. The item can be a string, a custom class or a Nav widget (defaults if no class specified. | ||||
| 	 * @param mixed $item the item to render. If array, it is assumed the configuration of a widget being `class` | ||||
| 	 * required and if not specified, then defaults to `yii\bootstrap\Nav`. | ||||
| 	 * @return string the rendering result. | ||||
| 	 * @throws InvalidConfigException | ||||
| 	 */ | ||||
| 	protected function renderItem($item) | ||||
| 	{ | ||||
| 		if (is_string($item)) { | ||||
| 			return $item; | ||||
| 		} | ||||
| 		$config = ArrayHelper::getValue($item, 'options', array()); | ||||
| 		$config['clientOptions'] = false; | ||||
| 
 | ||||
| 		$class = ArrayHelper::getValue($item, 'class', 'yii\bootstrap\Nav'); | ||||
| 
 | ||||
| 		return $class::widget($config); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders collapsible toggle button. | ||||
| 	 * @return string the rendering toggle button. | ||||
| 	 */ | ||||
| 	protected function renderToggleButton() | ||||
| 	{ | ||||
| 		$items = array(); | ||||
| 		for ($i = 0; $i < 3; $i++) { | ||||
| 			$items[] = Html::tag('span', '', array('class' => 'icon-bar')); | ||||
| 		} | ||||
| 		return Html::a(implode("\n", $items), null, array( | ||||
| 			'class' => 'btn btn-navbar', | ||||
| 			'data-toggle' => 'collapse', | ||||
| 			'data-target' => 'div.navbar-collapse', | ||||
| 		)); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,232 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\i18n; | ||||
| 
 | ||||
| use Yii; | ||||
| use IntlDateFormatter; | ||||
| use NumberFormatter; | ||||
| use DateTime; | ||||
| use yii\base\InvalidConfigException; | ||||
| 
 | ||||
| /** | ||||
|  * Formatter is the localized version of [[\yii\base\Formatter]]. | ||||
|  * | ||||
|  * Formatter requires the PHP "intl" extension to be installed. Formatter supports localized | ||||
|  * formatting of date, time and numbers, based on the current [[locale]]. | ||||
|  * | ||||
|  * @author Qiang Xue <qiang.xue@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Formatter extends \yii\base\Formatter | ||||
| { | ||||
| 	/** | ||||
| 	 * @var string the locale ID that is used to localize the date and number formatting. | ||||
| 	 * If not set, [[\yii\base\Application::language]] will be used. | ||||
| 	 */ | ||||
| 	public $locale; | ||||
| 	/** | ||||
| 	 * @var string the default format string to be used to format a date using PHP date() function. | ||||
| 	 */ | ||||
| 	public $dateFormat = 'short'; | ||||
| 	/** | ||||
| 	 * @var string the default format string to be used to format a time using PHP date() function. | ||||
| 	 */ | ||||
| 	public $timeFormat = 'short'; | ||||
| 	/** | ||||
| 	 * @var string the default format string to be used to format a date and time using PHP date() function. | ||||
| 	 */ | ||||
| 	public $datetimeFormat = 'short'; | ||||
| 	/** | ||||
| 	 * @var array the options to be set for the NumberFormatter objects. Please refer to | ||||
| 	 */ | ||||
| 	public $numberFormatOptions = array(); | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Initializes the component. | ||||
| 	 * This method will check if the "intl" PHP extension is installed and set the | ||||
| 	 * default value of [[locale]]. | ||||
| 	 * @throws InvalidConfigException if the "intl" PHP extension is not installed. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		if (!extension_loaded('intl')) { | ||||
| 			throw new InvalidConfigException('The "intl" PHP extension is not install. It is required to format data values in localized formats.'); | ||||
| 		} | ||||
| 		if ($this->locale === null) { | ||||
| 			$this->locale = Yii::$app->language; | ||||
| 		} | ||||
| 		parent::init(); | ||||
| 	} | ||||
| 
 | ||||
| 	private $_dateFormats = array( | ||||
| 		'short' => IntlDateFormatter::SHORT, | ||||
| 		'medium' => IntlDateFormatter::MEDIUM, | ||||
| 		'long' => IntlDateFormatter::LONG, | ||||
| 		'full' => IntlDateFormatter::FULL, | ||||
| 	); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a date. | ||||
| 	 * @param integer|string|DateTime $value the value to be formatted. The following | ||||
| 	 * types of value are supported: | ||||
| 	 * | ||||
| 	 * - an integer representing a UNIX timestamp | ||||
| 	 * - a string that can be parsed into a UNIX timestamp via `strtotime()` | ||||
| 	 * - a PHP DateTime object | ||||
| 	 * | ||||
| 	 * @param string $format the format used to convert the value into a date string. | ||||
| 	 * If null, [[dateFormat]] will be used. The format string should be the one | ||||
| 	 * that can be recognized by the PHP `date()` function. | ||||
| 	 * @return string the formatted result | ||||
| 	 * @see dateFormat | ||||
| 	 */ | ||||
| 	public function asDate($value, $format = null) | ||||
| 	{ | ||||
| 		$value = $this->normalizeDatetimeValue($value); | ||||
| 		if ($format === null) { | ||||
| 			$format = $this->dateFormat; | ||||
| 		} | ||||
| 		if (isset($this->_dateFormats[$format])) { | ||||
| 			$formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], IntlDateFormatter::NONE); | ||||
| 		} else { | ||||
| 			$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); | ||||
| 			$formatter->setPattern($format); | ||||
| 		} | ||||
| 		return $formatter->format($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a time. | ||||
| 	 * @param integer|string|DateTime $value the value to be formatted. The following | ||||
| 	 * types of value are supported: | ||||
| 	 * | ||||
| 	 * - an integer representing a UNIX timestamp | ||||
| 	 * - a string that can be parsed into a UNIX timestamp via `strtotime()` | ||||
| 	 * - a PHP DateTime object | ||||
| 	 * | ||||
| 	 * @param string $format the format used to convert the value into a date string. | ||||
| 	 * If null, [[dateFormat]] will be used. The format string should be the one | ||||
| 	 * that can be recognized by the PHP `date()` function. | ||||
| 	 * @return string the formatted result | ||||
| 	 * @see timeFormat | ||||
| 	 */ | ||||
| 	public function asTime($value, $format = null) | ||||
| 	{ | ||||
| 		$value = $this->normalizeDatetimeValue($value); | ||||
| 		if ($format === null) { | ||||
| 			$format = $this->timeFormat; | ||||
| 		} | ||||
| 		if (isset($this->_dateFormats[$format])) { | ||||
| 			$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, $this->_dateFormats[$format]); | ||||
| 		} else { | ||||
| 			$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); | ||||
| 			$formatter->setPattern($format); | ||||
| 		} | ||||
| 		return $formatter->format($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a datetime. | ||||
| 	 * @param integer|string|DateTime $value the value to be formatted. The following | ||||
| 	 * types of value are supported: | ||||
| 	 * | ||||
| 	 * - an integer representing a UNIX timestamp | ||||
| 	 * - a string that can be parsed into a UNIX timestamp via `strtotime()` | ||||
| 	 * - a PHP DateTime object | ||||
| 	 * | ||||
| 	 * @param string $format the format used to convert the value into a date string. | ||||
| 	 * If null, [[dateFormat]] will be used. The format string should be the one | ||||
| 	 * that can be recognized by the PHP `date()` function. | ||||
| 	 * @return string the formatted result | ||||
| 	 * @see datetimeFormat | ||||
| 	 */ | ||||
| 	public function asDatetime($value, $format = null) | ||||
| 	{ | ||||
| 		$value = $this->normalizeDatetimeValue($value); | ||||
| 		if ($format === null) { | ||||
| 			$format = $this->datetimeFormat; | ||||
| 		} | ||||
| 		if (isset($this->_dateFormats[$format])) { | ||||
| 			$formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], $this->_dateFormats[$format]); | ||||
| 		} else { | ||||
| 			$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); | ||||
| 			$formatter->setPattern($format); | ||||
| 		} | ||||
| 		return $formatter->format($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a decimal number. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @param string $format the format to be used. Please refer to [ICU manual](http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) | ||||
| 	 * for details on how to specify a format. | ||||
| 	 * @return string the formatted result. | ||||
| 	 */ | ||||
| 	public function asDecimal($value, $format = null) | ||||
| 	{ | ||||
| 		return $this->createNumberFormatter(NumberFormatter::DECIMAL, $format)->format($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a currency number. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @param string $currency the 3-letter ISO 4217 currency code indicating the currency to use. | ||||
| 	 * @param string $format the format to be used. Please refer to [ICU manual](http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) | ||||
| 	 * for details on how to specify a format. | ||||
| 	 * @return string the formatted result. | ||||
| 	 */ | ||||
| 	public function asCurrency($value, $currency = 'USD', $format = null) | ||||
| 	{ | ||||
| 		return $this->createNumberFormatter(NumberFormatter::CURRENCY, $format)->formatCurrency($value, $currency); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a percent number. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @param string $format the format to be used. Please refer to [ICU manual](http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) | ||||
| 	 * for details on how to specify a format. | ||||
| 	 * @return string the formatted result. | ||||
| 	 */ | ||||
| 	public function asPercent($value, $format = null) | ||||
| 	{ | ||||
| 		return $this->createNumberFormatter(NumberFormatter::PERCENT, $format)->format($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Formats the value as a scientific number. | ||||
| 	 * @param mixed $value the value to be formatted | ||||
| 	 * @param string $format the format to be used. Please refer to [ICU manual](http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) | ||||
| 	 * for details on how to specify a format. | ||||
| 	 * @return string the formatted result. | ||||
| 	 */ | ||||
| 	public function asScientific($value, $format = null) | ||||
| 	{ | ||||
| 		return $this->createNumberFormatter(NumberFormatter::SCIENTIFIC, $format)->format($value); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Creates a number formatter based on the given type and format. | ||||
| 	 * @param integer $type the type of the number formatter | ||||
| 	 * @param string $format the format to be used | ||||
| 	 * @return NumberFormatter the created formatter instance | ||||
| 	 */ | ||||
| 	protected function createNumberFormatter($type, $format) | ||||
| 	{ | ||||
| 		$formatter = new NumberFormatter($this->locale, $type); | ||||
| 		if ($format !== null) { | ||||
| 			$formatter->setPattern($format); | ||||
| 		} | ||||
| 		if (!empty($this->numberFormatOptions)) { | ||||
| 			foreach ($this->numberFormatOptions as $name => $attribute) { | ||||
| 				$formatter->setAttribute($name, $attribute); | ||||
| 			} | ||||
| 		} | ||||
| 		return $formatter; | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,52 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\jui; | ||||
| 
 | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * Draggable renders an draggable jQuery UI widget. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * Draggable::begin(array( | ||||
|  *     'clientOptions' => array( | ||||
|  *         'grid' => array(50, 20), | ||||
|  *     ), | ||||
|  * )); | ||||
|  * | ||||
|  * echo 'Draggable contents here...'; | ||||
|  * | ||||
|  * Draggable::end(); | ||||
|  * ``` | ||||
|  * | ||||
|  * @see http://api.jqueryui.com/draggable/ | ||||
|  * @author Alexander Kochetov <creocoder@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Draggable extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 		echo Html::beginTag('div', $this->options) . "\n"; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		echo Html::endTag('div') . "\n"; | ||||
| 		$this->registerWidget('draggable', false); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,52 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\jui; | ||||
| 
 | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * Droppable renders an droppable jQuery UI widget. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * Droppable::begin(array( | ||||
|  *     'clientOptions' => array( | ||||
|  *         'accept' => '.special', | ||||
|  *     ), | ||||
|  * )); | ||||
|  * | ||||
|  * echo 'Droppable body here...'; | ||||
|  * | ||||
|  * Droppable::end(); | ||||
|  * ``` | ||||
|  * | ||||
|  * @see http://api.jqueryui.com/droppable/ | ||||
|  * @author Alexander Kochetov <creocoder@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Droppable extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 		echo Html::beginTag('div', $this->options) . "\n"; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		echo Html::endTag('div') . "\n"; | ||||
| 		$this->registerWidget('droppable', false); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,52 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\jui; | ||||
| 
 | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * Resizable renders an resizable jQuery UI widget. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * Resizable::begin(array( | ||||
|  *     'clientOptions' => array( | ||||
|  *         'grid' => array(20, 10), | ||||
|  *     ), | ||||
|  * )); | ||||
|  * | ||||
|  * echo 'Resizable contents here...'; | ||||
|  * | ||||
|  * Resizable::end(); | ||||
|  * ``` | ||||
|  * | ||||
|  * @see http://api.jqueryui.com/resizable/ | ||||
|  * @author Alexander Kochetov <creocoder@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Resizable extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 		echo Html::beginTag('div', $this->options) . "\n"; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		echo Html::endTag('div') . "\n"; | ||||
| 		$this->registerWidget('resizable'); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,116 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\jui; | ||||
| 
 | ||||
| use yii\base\InvalidConfigException; | ||||
| use yii\helpers\ArrayHelper; | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * Selectable renders a selectable jQuery UI widget. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * echo Selectable::widget(array( | ||||
|  *     'items' => array( | ||||
|  *         'Item 1', | ||||
|  *         array( | ||||
|  *             'content' => 'Item2', | ||||
|  *         ), | ||||
|  *         array( | ||||
|  *             'content' => 'Item3', | ||||
|  *             'options' => array( | ||||
|  *                 'tag' => 'li', | ||||
|  *             ), | ||||
|  *         ), | ||||
|  *     ), | ||||
|  *     'options' => array( | ||||
|  *         'tag' => 'ul', | ||||
|  *     ), | ||||
|  *     'itemOptions' => array( | ||||
|  *         'tag' => 'li', | ||||
|  *     ), | ||||
|  *     'clientOptions' => array( | ||||
|  *         'tolerance' => 'fit', | ||||
|  *     ), | ||||
|  * )); | ||||
|  * ``` | ||||
|  * | ||||
|  * @see http://api.jqueryui.com/selectable/ | ||||
|  * @author Alexander Kochetov <creocoder@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Selectable extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * @var array the HTML attributes for the widget container tag. The following special options are recognized: | ||||
| 	 * | ||||
| 	 * - tag: string, defaults to "ul", the tag name of the container tag of this widget | ||||
| 	 */ | ||||
| 	public $options = array(); | ||||
| 	/** | ||||
| 	 * @var array list of selectable items. Each item can be a string representing the item content | ||||
| 	 * or an array of the following structure: | ||||
| 	 * | ||||
| 	 * ~~~ | ||||
| 	 * array( | ||||
| 	 *     'content' => 'item content', | ||||
| 	 *     // the HTML attributes of the item container tag. This will overwrite "itemOptions". | ||||
| 	 *     'options' => array(), | ||||
| 	 * ) | ||||
| 	 * ~~~ | ||||
| 	 */ | ||||
| 	public $items = array(); | ||||
| 	/** | ||||
| 	 * @var array list of HTML attributes for the item container tags. This will be overwritten | ||||
| 	 * by the "options" set in individual [[items]]. The following special options are recognized: | ||||
| 	 * | ||||
| 	 * - tag: string, defaults to "li", the tag name of the item container tags. | ||||
| 	 */ | ||||
| 	public $itemOptions = array(); | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		$options = $this->options; | ||||
| 		$tag = ArrayHelper::remove($options, 'tag', 'ul'); | ||||
| 		echo Html::beginTag($tag, $options) . "\n"; | ||||
| 		echo $this->renderItems() . "\n"; | ||||
| 		echo Html::endTag($tag) . "\n"; | ||||
| 		$this->registerWidget('selectable'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders selectable items as specified on [[items]]. | ||||
| 	 * @return string the rendering result. | ||||
| 	 * @throws InvalidConfigException. | ||||
| 	 */ | ||||
| 	public function renderItems() | ||||
| 	{ | ||||
| 		$items = array(); | ||||
| 		foreach ($this->items as $item) { | ||||
| 			$options = $this->itemOptions; | ||||
| 			$tag = ArrayHelper::remove($options, 'tag', 'li'); | ||||
| 			if (is_array($item)) { | ||||
| 				if (!isset($item['content'])) { | ||||
| 					throw new InvalidConfigException("The 'content' option is required."); | ||||
| 				} | ||||
| 				$options = array_merge($options, ArrayHelper::getValue($item, 'options', array())); | ||||
| 				$tag = ArrayHelper::remove($options, 'tag', $tag); | ||||
| 				$items[] = Html::tag($tag, $item['content'], $options); | ||||
| 			} else { | ||||
| 				$items[] = Html::tag($tag, $item, $options); | ||||
| 			} | ||||
| 		} | ||||
| 		return implode("\n", $items); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,66 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\jui; | ||||
| 
 | ||||
| use Yii; | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * Spinner renders an spinner jQuery UI widget. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * echo Spinner::widget(array( | ||||
|  *     'model' => $model, | ||||
|  *     'attribute' => 'country', | ||||
|  *     'clientOptions' => array( | ||||
|  *         'step' => 2, | ||||
|  *     ), | ||||
|  * )); | ||||
|  * ``` | ||||
|  * | ||||
|  * The following example will use the name property instead: | ||||
|  * | ||||
|  * ```php | ||||
|  * echo Spinner::widget(array( | ||||
|  *     'name'  => 'country', | ||||
|  *     'clientOptions' => array( | ||||
|  *         'step' => 2, | ||||
|  *     ), | ||||
|  * )); | ||||
|  *``` | ||||
|  * | ||||
|  * @see http://api.jqueryui.com/spinner/ | ||||
|  * @author Alexander Kochetov <creocoder@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Spinner extends InputWidget | ||||
| { | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		echo $this->renderWidget(); | ||||
| 		$this->registerWidget('spinner'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the Spinner widget. | ||||
| 	 * @return string the rendering result. | ||||
| 	 */ | ||||
| 	public function renderWidget() | ||||
| 	{ | ||||
| 		if ($this->hasModel()) { | ||||
| 			return Html::activeTextInput($this->model, $this->attribute, $this->options); | ||||
| 		} else { | ||||
| 			return Html::textInput($this->name, $this->value, $this->options); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,90 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\web; | ||||
| 
 | ||||
| use Yii; | ||||
| use yii\base\ActionEvent; | ||||
| use yii\base\Behavior; | ||||
| use yii\base\HttpException; | ||||
| 
 | ||||
| /** | ||||
|  * VerbFilter is an action filter that filters by HTTP request methods. | ||||
|  * | ||||
|  * It allows to define allowed HTTP request methods for each action and will throw | ||||
|  * an HTTP 405 error when the method is not allowed. | ||||
|  * | ||||
|  * To use VerbFilter, declare it in the `behaviors()` method of your controller class. | ||||
|  * For example, the following declarations will define a typical set of allowed | ||||
|  * request methods for REST CRUD actions. | ||||
|  * | ||||
|  * ~~~ | ||||
|  * public function behaviors() | ||||
|  * { | ||||
|  *     return array( | ||||
|  *         'verbs' => array( | ||||
|  *             'class' => \yii\web\VerbFilter::className(), | ||||
|  *             'actions' => array( | ||||
|  *                 'index'  => array('get'), | ||||
|  *                 'view'   => array('get'), | ||||
|  *                 'create' => array('get', 'post'), | ||||
|  *                 'update' => array('get', 'put', 'post'), | ||||
|  *                 'delete' => array('post', 'delete'), | ||||
|  *             ), | ||||
|  *         ), | ||||
|  *     ); | ||||
|  * } | ||||
|  * ~~~ | ||||
|  * | ||||
|  * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7 | ||||
|  * @author Carsten Brandt <mail@cebe.cc> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class VerbFilter extends Behavior | ||||
| { | ||||
| 	/** | ||||
| 	 * @var array this property defines the allowed request methods for each action. | ||||
| 	 * For each action that should only support limited set of request methods | ||||
| 	 * you add an entry with the action id as array key and an array of | ||||
| 	 * allowed methods (e.g. GET, HEAD, PUT) as the value. | ||||
| 	 * If an action is not listed all request methods are considered allowed. | ||||
| 	 */ | ||||
| 	public $actions = array(); | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Declares event handlers for the [[owner]]'s events. | ||||
| 	 * @return array events (array keys) and the corresponding event handler methods (array values). | ||||
| 	 */ | ||||
| 	public function events() | ||||
| 	{ | ||||
| 		return array( | ||||
| 			Controller::EVENT_BEFORE_ACTION => 'beforeAction', | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param ActionEvent $event | ||||
| 	 * @return boolean | ||||
| 	 * @throws \yii\base\HttpException when the request method is not allowed. | ||||
| 	 */ | ||||
| 	public function beforeAction($event) | ||||
| 	{ | ||||
| 		$action = $event->action->id; | ||||
| 		if (isset($this->actions[$action])) { | ||||
| 			$verb = Yii::$app->getRequest()->getRequestMethod(); | ||||
| 			$allowed = array_map('strtoupper', $this->actions[$action]); | ||||
| 			if (!in_array($verb, $allowed)) { | ||||
| 				$event->isValid = false; | ||||
| 				// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7 | ||||
| 				header('Allow: ' . implode(', ', $allowed)); | ||||
| 				throw new HttpException(405, 'Method Not Allowed. This url can only handle the following request methods: ' . implode(', ', $allowed)); | ||||
| 			} | ||||
| 		} | ||||
| 		return $event->isValid; | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,64 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\widgets; | ||||
| 
 | ||||
| use Yii; | ||||
| use yii\base\Widget; | ||||
| use yii\base\Model; | ||||
| use yii\base\InvalidConfigException; | ||||
| 
 | ||||
| /** | ||||
|  * InputWidget is the base class for widgets that collect user inputs. | ||||
|  * | ||||
|  * An input widget can be associated with a data model and an attribute, | ||||
|  * or a name and a value. If the former, the name and the value will | ||||
|  * be generated automatically. | ||||
|  * | ||||
|  * @author Qiang Xue <qiang.xue@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class InputWidget extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * @var Model the data model that this widget is associated with. | ||||
| 	 */ | ||||
| 	public $model; | ||||
| 	/** | ||||
| 	 * @var string the model attribute that this widget is associated with. | ||||
| 	 */ | ||||
| 	public $attribute; | ||||
| 	/** | ||||
| 	 * @var string the input name. This must be set if [[model]] and [[attribute]] are not set. | ||||
| 	 */ | ||||
| 	public $name; | ||||
| 	/** | ||||
| 	 * @var string the input value. | ||||
| 	 */ | ||||
| 	public $value; | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 * If you override this method, make sure you call the parent implementation first. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		if (!$this->hasModel() && $this->name === null) { | ||||
| 			throw new InvalidConfigException("Either 'name' or 'model' and 'attribute' properties must be specified."); | ||||
| 		} | ||||
| 		parent::init(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @return boolean whether this widget is associated with a data model. | ||||
| 	 */ | ||||
| 	protected function hasModel() | ||||
| 	{ | ||||
| 		return $this->model instanceof Model && $this->attribute !== null; | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,136 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\widgets; | ||||
| 
 | ||||
| use yii\base\InvalidConfigException; | ||||
| use yii\helpers\Html; | ||||
| use yii\helpers\Json; | ||||
| use yii\web\JsExpression; | ||||
| 
 | ||||
| /** | ||||
|  * MaskedInput generates a masked text input. | ||||
|  * | ||||
|  * MaskedInput is similar to [[Html::textInput()]] except that | ||||
|  * an input mask will be used to force users to enter properly formatted data, | ||||
|  * such as phone numbers, social security numbers. | ||||
|  *  | ||||
|  * To use MaskedInput, you must set the [[mask]] property. The following example | ||||
|  * shows how to use MaskedInput to collect phone numbers: | ||||
|  *  | ||||
|  * ~~~ | ||||
|  * echo MaskedInput::widget(array( | ||||
|  *     'name' => 'phone', | ||||
|  *     'mask' => '999-999-9999', | ||||
|  * )); | ||||
|  * ~~~ | ||||
|  *  | ||||
|  * The masked text field is implemented based on the [jQuery masked input plugin](http://digitalbush.com/projects/masked-input-plugin). | ||||
|  * | ||||
|  * @author Qiang Xue <qiang.xue@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class MaskedInput extends InputWidget | ||||
| { | ||||
| 	/** | ||||
| 	 * @var string the input mask (e.g. '99/99/9999' for date input). The following characters are predefined: | ||||
| 	 * | ||||
| 	 * - `a`: represents an alpha character (A-Z,a-z) | ||||
| 	 * - `9`: represents a numeric character (0-9) | ||||
| 	 * - `*`: represents an alphanumeric character (A-Z,a-z,0-9) | ||||
| 	 * - `?`: anything listed after '?' within the mask is considered optional user input | ||||
| 	 * | ||||
| 	 * Additional characters can be defined by specifying the [[charMap]] property. | ||||
| 	 */ | ||||
| 	public $mask; | ||||
| 	/** | ||||
| 	 * @var array the mapping between mask characters and the corresponding patterns. | ||||
| 	 * For example, `array('~' => '[+-]')` specifies that the '~' character expects '+' or '-' input. | ||||
| 	 * Defaults to null, meaning using the map as described in [[mask]]. | ||||
| 	 */ | ||||
| 	public $charMap; | ||||
| 	/** | ||||
| 	 * @var string the character prompting for user input. Defaults to underscore '_'. | ||||
| 	 */ | ||||
| 	public $placeholder; | ||||
| 	/** | ||||
| 	 * @var string a JavaScript function callback that will be invoked when user finishes the input. | ||||
| 	 */ | ||||
| 	public $completed; | ||||
| 	/** | ||||
| 	 * @var array the HTML attributes for the input tag. | ||||
| 	 */ | ||||
| 	public $options = array(); | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 * @throws InvalidConfigException if the "mask" property is not set. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 		if (empty($this->mask)) { | ||||
| 			throw new InvalidConfigException('The "mask" property must be set.'); | ||||
| 		} | ||||
| 
 | ||||
| 		if (!isset($this->options['id'])) { | ||||
| 			$this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId(); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Runs the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		if ($this->hasModel()) { | ||||
| 			echo Html::activeTextInput($this->model, $this->attribute, $this->options); | ||||
| 		} else { | ||||
| 			echo Html::textInput($this->name, $this->value, $this->options); | ||||
| 		} | ||||
| 		$this->registerClientScript(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Registers the needed JavaScript. | ||||
| 	 */ | ||||
| 	public function registerClientScript() | ||||
| 	{ | ||||
| 		$options = $this->getClientOptions(); | ||||
| 		$options = empty($options) ? '' : ',' . Json::encode($options); | ||||
| 		$js = ''; | ||||
| 		if (is_array($this->charMap) && !empty($this->charMap)) { | ||||
| 			$js .= 'jQuery.mask.definitions=' . Json::encode($this->charMap) . ";\n"; | ||||
| 		} | ||||
| 		$id = $this->options['id']; | ||||
| 		$js .= "jQuery(\"#{$id}\").mask(\"{$this->mask}\"{$options});"; | ||||
| 		$this->getView()->registerAssetBundle('yii/maskedinput'); | ||||
| 		$this->getView()->registerJs($js); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @return array the options for the text field | ||||
| 	 */ | ||||
| 	protected function getClientOptions() | ||||
| 	{ | ||||
| 		$options = array(); | ||||
| 		if ($this->placeholder !== null) { | ||||
| 			$options['placeholder'] = $this->placeholder; | ||||
| 		} | ||||
| 
 | ||||
| 		if ($this->completed !== null) { | ||||
| 			if ($this->completed instanceof JsExpression) { | ||||
| 				$options['completed'] = $this->completed; | ||||
| 			} else { | ||||
| 				$options['completed'] = new JsExpression($this->completed); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return $options; | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,179 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| namespace yiiunit\framework\base; | ||||
| 
 | ||||
| use yii\base\Formatter; | ||||
| use yiiunit\TestCase; | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @author Qiang Xue <qiang.xue@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class FormatterTest extends TestCase | ||||
| { | ||||
| 	/** | ||||
| 	 * @var Formatter | ||||
| 	 */ | ||||
| 	protected $formatter; | ||||
| 
 | ||||
| 	protected function setUp() | ||||
| 	{ | ||||
| 		parent::setUp(); | ||||
| 		$this->mockApplication(); | ||||
| 		$this->formatter = new Formatter(); | ||||
| 	} | ||||
| 
 | ||||
| 	protected function tearDown() | ||||
| 	{ | ||||
| 		parent::tearDown(); | ||||
| 		$this->formatter = null; | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsRaw() | ||||
| 	{ | ||||
| 		$value = '123'; | ||||
| 		$this->assertSame($value, $this->formatter->asRaw($value)); | ||||
| 		$value = 123; | ||||
| 		$this->assertSame($value, $this->formatter->asRaw($value)); | ||||
| 		$value = '<>'; | ||||
| 		$this->assertSame($value, $this->formatter->asRaw($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsText() | ||||
| 	{ | ||||
| 		$value = '123'; | ||||
| 		$this->assertSame($value, $this->formatter->asText($value)); | ||||
| 		$value = 123; | ||||
| 		$this->assertSame("$value", $this->formatter->asText($value)); | ||||
| 		$value = '<>'; | ||||
| 		$this->assertSame('<>', $this->formatter->asText($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsNtext() | ||||
| 	{ | ||||
| 		$value = '123'; | ||||
| 		$this->assertSame($value, $this->formatter->asNtext($value)); | ||||
| 		$value = 123; | ||||
| 		$this->assertSame("$value", $this->formatter->asNtext($value)); | ||||
| 		$value = '<>'; | ||||
| 		$this->assertSame('<>', $this->formatter->asNtext($value)); | ||||
| 		$value = "123\n456"; | ||||
| 		$this->assertSame("123<br />\n456", $this->formatter->asNtext($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsParagraphs() | ||||
| 	{ | ||||
| 		$value = '123'; | ||||
| 		$this->assertSame("<p>$value</p>", $this->formatter->asParagraphs($value)); | ||||
| 		$value = 123; | ||||
| 		$this->assertSame("<p>$value</p>", $this->formatter->asParagraphs($value)); | ||||
| 		$value = '<>'; | ||||
| 		$this->assertSame('<p><></p>', $this->formatter->asParagraphs($value)); | ||||
| 		$value = "123\n456"; | ||||
| 		$this->assertSame("<p>123\n456</p>", $this->formatter->asParagraphs($value)); | ||||
| 		$value = "123\n\n456"; | ||||
| 		$this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value)); | ||||
| 		$value = "123\n\n\n456"; | ||||
| 		$this->assertSame("<p>123</p>\n<p>456</p>", $this->formatter->asParagraphs($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsHtml() | ||||
| 	{ | ||||
| 		// todo: dependency on HtmlPurifier | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsEmail() | ||||
| 	{ | ||||
| 		$value = 'test@sample.com'; | ||||
| 		$this->assertSame("<a href=\"mailto:$value\">$value</a>", $this->formatter->asEmail($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsImage() | ||||
| 	{ | ||||
| 		$value = 'http://sample.com/img.jpg'; | ||||
| 		$this->assertSame("<img src=\"$value\" alt=\"\" />", $this->formatter->asImage($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsBoolean() | ||||
| 	{ | ||||
| 		$value = true; | ||||
| 		$this->assertSame('Yes', $this->formatter->asBoolean($value)); | ||||
| 		$value = false; | ||||
| 		$this->assertSame('No', $this->formatter->asBoolean($value)); | ||||
| 		$value = "111"; | ||||
| 		$this->assertSame('Yes', $this->formatter->asBoolean($value)); | ||||
| 		$value = ""; | ||||
| 		$this->assertSame('No', $this->formatter->asBoolean($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsDate() | ||||
| 	{ | ||||
| 		$value = time(); | ||||
| 		$this->assertSame(date('Y/m/d', $value), $this->formatter->asDate($value)); | ||||
| 		$this->assertSame(date('Y-m-d', $value), $this->formatter->asDate($value, 'Y-m-d')); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsTime() | ||||
| 	{ | ||||
| 		$value = time(); | ||||
| 		$this->assertSame(date('h:i:s A', $value), $this->formatter->asTime($value)); | ||||
| 		$this->assertSame(date('h:i:s', $value), $this->formatter->asTime($value, 'h:i:s')); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsDatetime() | ||||
| 	{ | ||||
| 		$value = time(); | ||||
| 		$this->assertSame(date('Y/m/d h:i:s A', $value), $this->formatter->asDatetime($value)); | ||||
| 		$this->assertSame(date('Y-m-d h:i:s', $value), $this->formatter->asDatetime($value, 'Y-m-d h:i:s')); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsInteger() | ||||
| 	{ | ||||
| 		$value = 123; | ||||
| 		$this->assertSame("$value", $this->formatter->asInteger($value)); | ||||
| 		$value = 123.23; | ||||
| 		$this->assertSame("123", $this->formatter->asInteger($value)); | ||||
| 		$value = 'a'; | ||||
| 		$this->assertSame("0", $this->formatter->asInteger($value)); | ||||
| 		$value = -123.23; | ||||
| 		$this->assertSame("-123", $this->formatter->asInteger($value)); | ||||
| 		$value = "-123abc"; | ||||
| 		$this->assertSame("-123", $this->formatter->asInteger($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsDouble() | ||||
| 	{ | ||||
| 		$value = 123.12; | ||||
| 		$this->assertSame("123.12", $this->formatter->asDouble($value)); | ||||
| 		$this->assertSame("123.1", $this->formatter->asDouble($value, 1)); | ||||
| 		$this->assertSame("123", $this->formatter->asDouble($value, 0)); | ||||
| 		$value = 123; | ||||
| 		$this->assertSame("123.00", $this->formatter->asDouble($value)); | ||||
| 		$this->formatter->decimalSeparator = ','; | ||||
| 		$value = 123.12; | ||||
| 		$this->assertSame("123,12", $this->formatter->asDouble($value)); | ||||
| 		$this->assertSame("123,1", $this->formatter->asDouble($value, 1)); | ||||
| 		$this->assertSame("123", $this->formatter->asDouble($value, 0)); | ||||
| 		$value = 123123.123; | ||||
| 		$this->assertSame("123123,12", $this->formatter->asDouble($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsNumber() | ||||
| 	{ | ||||
| 		$value = 123123.123; | ||||
| 		$this->assertSame("123,123", $this->formatter->asNumber($value)); | ||||
| 		$this->assertSame("123,123.12", $this->formatter->asNumber($value, 2)); | ||||
| 		$this->formatter->decimalSeparator = ','; | ||||
| 		$this->formatter->thousandSeparator = ' '; | ||||
| 		$this->assertSame("123 123", $this->formatter->asNumber($value)); | ||||
| 		$this->assertSame("123 123,12", $this->formatter->asNumber($value, 2)); | ||||
| 		$this->formatter->thousandSeparator = ''; | ||||
| 		$this->assertSame("123123", $this->formatter->asNumber($value)); | ||||
| 		$this->assertSame("123123,12", $this->formatter->asNumber($value, 2)); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,88 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yiiunit\framework\i18n; | ||||
| 
 | ||||
| use yii\i18n\Formatter; | ||||
| use yiiunit\TestCase; | ||||
| 
 | ||||
| /** | ||||
|  * @author Qiang Xue <qiang.xue@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class FormatterTest extends TestCase | ||||
| { | ||||
| 	/** | ||||
| 	 * @var Formatter | ||||
| 	 */ | ||||
| 	protected $formatter; | ||||
| 
 | ||||
| 	protected function setUp() | ||||
| 	{ | ||||
| 		parent::setUp(); | ||||
| 		if (!extension_loaded('intl')) { | ||||
| 			$this->markTestSkipped('intl extension is required.'); | ||||
| 		} | ||||
| 		$this->mockApplication(); | ||||
| 		$this->formatter = new Formatter(array( | ||||
| 			'locale' => 'en_US', | ||||
| 		)); | ||||
| 	} | ||||
| 
 | ||||
| 	protected function tearDown() | ||||
| 	{ | ||||
| 		parent::tearDown(); | ||||
| 		$this->formatter = null; | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsDecimal() | ||||
| 	{ | ||||
| 		$value = '123'; | ||||
| 		$this->assertSame($value, $this->formatter->asDecimal($value)); | ||||
| 		$value = '123456'; | ||||
| 		$this->assertSame("123,456", $this->formatter->asDecimal($value)); | ||||
| 		$value = '-123456.123'; | ||||
| 		$this->assertSame("-123,456.123", $this->formatter->asDecimal($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsPercent() | ||||
| 	{ | ||||
| 		$value = '123'; | ||||
| 		$this->assertSame('12,300%', $this->formatter->asPercent($value)); | ||||
| 		$value = '0.1234'; | ||||
| 		$this->assertSame("12%", $this->formatter->asPercent($value)); | ||||
| 		$value = '-0.009343'; | ||||
| 		$this->assertSame("-1%", $this->formatter->asPercent($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsScientific() | ||||
| 	{ | ||||
| 		$value = '123'; | ||||
| 		$this->assertSame('1.23E2', $this->formatter->asScientific($value)); | ||||
| 		$value = '123456'; | ||||
| 		$this->assertSame("1.23456E5", $this->formatter->asScientific($value)); | ||||
| 		$value = '-123456.123'; | ||||
| 		$this->assertSame("-1.23456123E5", $this->formatter->asScientific($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testAsCurrency() | ||||
| 	{ | ||||
| 		$value = '123'; | ||||
| 		$this->assertSame('$123.00', $this->formatter->asCurrency($value)); | ||||
| 		$value = '123.456'; | ||||
| 		$this->assertSame("$123.46", $this->formatter->asCurrency($value)); | ||||
| 		$value = '-123456.123'; | ||||
| 		$this->assertSame("($123,456.12)", $this->formatter->asCurrency($value)); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testDate() | ||||
| 	{ | ||||
| 		$time = time(); | ||||
| 		$this->assertSame(date('n/j/y', $time), $this->formatter->asDate($time)); | ||||
| 		$this->assertSame(date('M j, Y', $time), $this->formatter->asDate($time, 'long')); | ||||
| 	} | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue