diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..c0564c2 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,4 @@ +service_name: travis-ci +src_dir: framework/yii +coverage_clover: tests/unit/runtime/coveralls/clover.xml +json_path: tests/unit/runtime/coveralls/coveralls-upload.json \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..818cb6a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +# Autodetect text files +* text=auto + +# ...Unless the name matches the following overriding patterns + +# Definitively text files +*.php text +*.css text +*.js text +*.txt text +*.md text +*.xml text +*.json text +*.bat text +*.sql text +*.xml text +*.yml text + +# Ensure those won't be messed up with +*.png binary +*.jpg binary +*.gif binary +*.ttf binary diff --git a/.gitignore b/.gitignore index 13fcf4a..5586ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,15 @@ nbproject Thumbs.db # composer vendor dir -/yii/vendor +/vendor # composer itself is not needed composer.phar +# composer.lock should not be committed as we always want the latest versions +/composer.lock + +# Mac DS_Store Files +.DS_Store + +# local phpunit config +/phpunit.xml diff --git a/.travis.yml b/.travis.yml index 01abd50..def1c47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,33 @@ language: php php: - - 5.3 - 5.4 - 5.5 +# - hhvm # commented until composer or hhvm get fixed: https://github.com/facebook/hhvm/issues/1347 -env: - - DB=mysql +services: + - redis-server + - memcached + - elasticsearch + - mongodb + +install: + - composer self-update && composer --version +# - composer require satooshi/php-coveralls 0.6.* --dev --prefer-dist + - tests/unit/data/travis/mongodb-setup.sh + - tests/unit/data/travis/apc-setup.sh + - tests/unit/data/travis/memcache-setup.sh + - tests/unit/data/travis/cubrid-setup.sh before_script: - - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS yiitest;'; fi" - - psql -U postgres -c 'drop database if exists yiitest;'; - - psql -U postgres -c 'create database yiitest;'; -script: phpunit \ No newline at end of file + - echo 'elasticsearch version ' && curl http://localhost:9200/ + - mysql -e 'CREATE DATABASE yiitest;'; + - psql -U postgres -c 'CREATE DATABASE yiitest;'; + - tests/unit/data/travis/sphinx-setup.sh + - mongo yii2test --eval 'db.addUser("travis", "test");' + +script: + - phpunit --coverage-text --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor + +#after_script: +# - php vendor/bin/coveralls diff --git a/LICENSE.md b/LICENSE.md index 6edcc4f..e98f03d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ 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) +Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) All rights reserved. Redistribution and use in source and binary forms, with or without @@ -29,4 +29,4 @@ 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. \ No newline at end of file +POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 9bd6480..d7020d9 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,57 @@ -Yii 2.0 Public Preview -====================== +Yii PHP Framework Version 2 +=========================== -Thank you for choosing Yii - a high-performance component-based PHP framework. +Thank you for choosing Yii 2 - a modern PHP framework designed for professional Web development. -If you are looking for a production-ready PHP framework, please use -[Yii v1.1](https://github.com/yiisoft/yii). +Yii 2 is a complete rewrite of its previous version Yii 1.1 which is one of the most popular PHP frameworks. +Yii 2 inherits the main spirit behind Yii for being simple, fast and highly extensible. +Yii 2 requires PHP 5.4 and embraces best practices and protocols found in modern Web application development. -Yii 2.0 is still under heavy development. We may make significant changes -without prior notices. **Yii 2.0 is not ready for production use yet.** +**Yii 2 is not ready for production use yet.** We may make significant changes without prior notices. +We expect to make the first stable release of Yii 2 in early 2014. + +If you mainly want to learn Yii with no real project development requirement, we highly recommend +you start with Yii 2 as it will be our main focus for the next few years. + +If you have a real project with tight schedule, you should stick to [Yii 1.1](https://github.com/yiisoft/yii) +which is the latest stable release of Yii. + + +[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2/v/stable.png)](https://packagist.org/packages/yiisoft/yii2) +[![Total Downloads](https://poser.pugx.org/yiisoft/yii2/downloads.png)](https://packagist.org/packages/yiisoft/yii2) [![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2) +[![Dependency Status](https://www.versioneye.com/php/yiisoft:yii2/dev-master/badge.png)](https://www.versioneye.com/php/yiisoft:yii2/dev-master) DIRECTORY STRUCTURE ------------------- - apps/ ready-to-use Web apps built on Yii 2 - basic/ a simple app supporting user login and contact page + apps/ ready-to-use application templates + advanced/ a template suitable for building sophisticated Web applications + basic/ a template suitable for building simple Web applications + benchmark/ an application demonstrating the performance of Yii build/ internally used build tools docs/ documentation - yii/ framework source files + extensions/ extensions + framework/ core framework code tests/ tests of the core framework code REQUIREMENTS ------------ -The minimum requirement by Yii is that your Web server supports PHP 5.3.?. +The minimum requirement by Yii is that your Web server supports PHP 5.4. DOCUMENTATION ------------- +A draft of the [Definitive Guide](docs/guide/index.md) is available. + For 1.1 users, you may refer to [Upgrading from Yii 1.1](docs/guide/upgrade-from-v1.md) to have a general idea of what has changed in 2.0. -We are writing more documentation to get you started and learn more in depth. - HOW TO PARTICIPATE ------------------ @@ -51,3 +66,5 @@ You may participate in the following ways: - Before you start, please adopt an existing issue (labelled with "ready for adoption") or start a new one to avoid duplicated efforts. - Please submit a merge request after you finish development. +In order to make it easier we've prepared [special `yii2-dev` Composer package](https://github.com/yiisoft/yii2/blob/master/docs/internals/getting-started.md). + diff --git a/apps/advanced/.gitignore b/apps/advanced/.gitignore index b1cf719..447bcd3 100644 --- a/apps/advanced/.gitignore +++ b/apps/advanced/.gitignore @@ -1 +1 @@ -/yii \ No newline at end of file +/yii diff --git a/apps/advanced/LICENSE.md b/apps/advanced/LICENSE.md index 6edcc4f..e98f03d 100644 --- a/apps/advanced/LICENSE.md +++ b/apps/advanced/LICENSE.md @@ -1,7 +1,7 @@ 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) +Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) All rights reserved. Redistribution and use in source and binary forms, with or without @@ -29,4 +29,4 @@ 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. \ No newline at end of file +POSSIBILITY OF SUCH DAMAGE. diff --git a/apps/advanced/README.md b/apps/advanced/README.md index f2abc1e..a512e17 100644 --- a/apps/advanced/README.md +++ b/apps/advanced/README.md @@ -1,17 +1,14 @@ Yii 2 Advanced Application Template =================================== -**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 Advanced Application Template is a skeleton Yii 2 application best for +developing complex Web applications with multiple tiers. +The template includes three tiers: front end, back end, and console, each of which +is a separate Yii application. -Thank you for using Yii 2 Advanced Application Template - an application template -that works out-of-box and can be easily customized to fit for your needs. - -Yii 2 Advanced Application Template is best suitable for large projects requiring frontend and backend separation, -deployment in different environments, configuration nesting etc. +The template is designed to work in a team development environment. It supports +deploying the application in different environments. DIRECTORY STRUCTURE @@ -34,7 +31,7 @@ backend models/ contains backend-specific model classes runtime/ contains files generated during runtime views/ contains view files for the Web application - www/ contains the entry script and Web resources + web/ contains the entry script and Web resources frontend assets/ contains application assets such as JavaScript and CSS config/ contains frontend configurations @@ -42,57 +39,40 @@ frontend models/ contains frontend-specific model classes runtime/ contains files generated during runtime views/ contains view files for the Web application - www/ contains the entry script and Web resources + web/ contains the entry script and Web resources vendor/ contains dependent 3rd-party packages environments/ contains environment-based overrides ``` - REQUIREMENTS ------------ -The minimum requirement by Yii is that your Web server supports PHP 5.3.?. +The minimum requirement by this application template that your Web server supports PHP 5.4.0. INSTALLATION ------------ -### Install via Composer - -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 application using the following command: - -~~~ -php composer.phar create-project --stability=dev yiisoft/yii2-app-advanced yii-advanced -~~~ +### Install from an Archive File +Extract the archive file downloaded from [yiiframework.com](http://www.yiiframework.com/download/) to +a directory named `advanced` that is directly under the Web root. -### Install from an Archive File +Then follow the instructions given in "GETTING STARTED". -This is not currently available. We will provide it when Yii 2 is formally released. +### Install via Composer -### Install from development repository +If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions +at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix). -If you've cloned the [Yii 2 framework main development repository](https://github.com/yiisoft/yii2) you -can bootstrap your application with: +You can then install the application using the following command: ~~~ -cd yii2/apps/advanced -php composer.phar create-project +php composer.phar create-project --stability=dev yiisoft/yii2-app-advanced advanced ~~~ -*Note: If the above command fails with `[RuntimeException] Not enough arguments.` run -`php composer.phar self-update` to obtain an updated version of composer which supports creating projects -from local packages.* - GETTING STARTED --------------- @@ -100,14 +80,11 @@ GETTING STARTED After you install the application, you have to conduct the following steps to initialize the installed application. You only need to do these once for all. -1. Execute the `init` command and select `dev` as environment. -2. Create a new database. It is assumed that MySQL InnoDB is used. If not, adjust `console/migrations/m130524_201442_init.php`. -3. In `common/config/params.php` set your database details in `components.db` values. +1. Run command `init` to initialize the application with a specific environment. +2. Create a new database and adjust the `components.db` configuration in `common/config/params.php` accordingly. +3. Run command `yii migrate` to apply DB migrations. Now you should be able to access: -- the frontend using the URL `http://localhost/yii-advanced/frontend/www/` -- the backend using the URL `http://localhost/yii-advanced/backend/www/` - -assuming `yii-advanced` is directly under the document root of your Web server. - +- the frontend using the URL `http://localhost/advanced/frontend/web/` +- the backend using the URL `http://localhost/advanced/backend/web/` diff --git a/apps/advanced/backend/assets/.gitkeep b/apps/advanced/backend/assets/.gitkeep deleted file mode 100644 index 72e8ffc..0000000 --- a/apps/advanced/backend/assets/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/apps/advanced/backend/assets/AppAsset.php b/apps/advanced/backend/assets/AppAsset.php new file mode 100644 index 0000000..bd5c3a0 --- /dev/null +++ b/apps/advanced/backend/assets/AppAsset.php @@ -0,0 +1,26 @@ + + * @since 2.0 + */ +class AppAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = ['css/site.css']; + public $js = []; + public $depends = [ + 'yii\web\YiiAsset', + 'yii\bootstrap\BootstrapAsset', + ]; +} diff --git a/apps/advanced/backend/config/assets.php b/apps/advanced/backend/config/assets.php deleted file mode 100644 index ee0d610..0000000 --- a/apps/advanced/backend/config/assets.php +++ /dev/null @@ -1,18 +0,0 @@ - array( - 'basePath' => '@wwwroot', - 'baseUrl' => '@www', - 'css' => array( - 'css/site.css', - ), - 'js' => array( - - ), - 'depends' => array( - 'yii', - 'yii/bootstrap/responsive', - ), - ), -); diff --git a/apps/advanced/backend/config/main.php b/apps/advanced/backend/config/main.php index 3140cd2..d1a45a7 100644 --- a/apps/advanced/backend/config/main.php +++ b/apps/advanced/backend/config/main.php @@ -1,5 +1,5 @@ 'app-backend', 'basePath' => dirname(__DIR__), - 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', - 'preload' => array('log'), + 'vendorPath' => $rootDir . '/vendor', + 'preload' => ['log'], 'controllerNamespace' => 'backend\controllers', - 'modules' => array( - ), - 'components' => array( + 'modules' => [], + 'extensions' => require($rootDir . '/vendor/yiisoft/extensions.php'), + 'components' => [ 'db' => $params['components.db'], 'cache' => $params['components.cache'], - 'user' => array( - 'class' => 'yii\web\User', + 'mail' => $params['components.mail'], + 'user' => [ 'identityClass' => 'common\models\User', - ), - 'assetManager' => array( - 'bundles' => require(__DIR__ . '/assets.php'), - ), - 'log' => array( - 'class' => 'yii\logging\Router', - 'targets' => array( - array( - 'class' => 'yii\logging\FileTarget', - 'levels' => array('error', 'warning'), - ), - ), - ), - ), + 'enableAutoLogin' => true, + ], + 'log' => [ + 'traceLevel' => YII_DEBUG ? 3 : 0, + 'targets' => [ + [ + 'class' => 'yii\log\FileTarget', + 'levels' => ['error', 'warning'], + ], + ], + ], + 'errorHandler' => [ + 'errorAction' => 'site/error', + ], + ], 'params' => $params, -); +]; diff --git a/apps/advanced/backend/config/params.php b/apps/advanced/backend/config/params.php index 1e197d0..0e625dc 100644 --- a/apps/advanced/backend/config/params.php +++ b/apps/advanced/backend/config/params.php @@ -1,5 +1,4 @@ 'admin@example.com', -); \ No newline at end of file +]; diff --git a/apps/advanced/backend/controllers/SiteController.php b/apps/advanced/backend/controllers/SiteController.php index 0306c97..ecf684c 100644 --- a/apps/advanced/backend/controllers/SiteController.php +++ b/apps/advanced/backend/controllers/SiteController.php @@ -8,26 +8,59 @@ use common\models\LoginForm; class SiteController extends Controller { + public function behaviors() + { + return [ + 'access' => [ + 'class' => \yii\web\AccessControl::className(), + 'rules' => [ + [ + 'actions' => ['login', 'error'], + 'allow' => true, + ], + [ + 'actions' => ['logout', 'index'], + 'allow' => true, + 'roles' => ['@'], + ], + ], + ], + ]; + } + + public function actions() + { + return [ + 'error' => [ + 'class' => 'yii\web\ErrorAction', + ], + ]; + } + public function actionIndex() { - echo $this->render('index'); + return $this->render('index'); } public function actionLogin() { + if (!\Yii::$app->user->isGuest) { + $this->goHome(); + } + $model = new LoginForm(); - if ($this->populate($_POST, $model) && $model->login()) { - Yii::$app->response->redirect(array('site/index')); + if ($model->load($_POST) && $model->login()) { + return $this->goBack(); } else { - echo $this->render('login', array( + return $this->render('login', [ 'model' => $model, - )); + ]); } } public function actionLogout() { - Yii::$app->getUser()->logout(); - Yii::$app->getResponse()->redirect(array('site/index')); + Yii::$app->user->logout(); + return $this->goHome(); } } diff --git a/apps/advanced/backend/views/layouts/main.php b/apps/advanced/backend/views/layouts/main.php index 44117f4..1857e62 100644 --- a/apps/advanced/backend/views/layouts/main.php +++ b/apps/advanced/backend/views/layouts/main.php @@ -1,64 +1,64 @@ registerAssetBundle('app'); +AppAsset::register($this); ?> -beginPage(); ?> +beginPage() ?> - + - - <?php echo Html::encode($this->title); ?> - head(); ?> + + <?= Html::encode($this->title) ?> + head() ?> -
- beginBody(); ?> -
-

My Company

+ beginBody() ?> + 'My Company', + 'brandUrl' => Yii::$app->homeUrl, + 'options' => [ + 'class' => 'navbar-inverse navbar-fixed-top', + ], + ]); + $menuItems = [ + ['label' => 'Home', 'url' => ['/site/index']], + ]; + if (Yii::$app->user->isGuest) { + $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; + } else { + $menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => ['/site/logout']]; + } + echo Nav::widget([ + 'options' => ['class' => 'navbar-nav navbar-right'], + 'items' => $menuItems, + ]); + NavBar::end(); + ?> - - +
+ isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], + ]) ?> +
- isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(), - )); ?> - - -
+
+
+

© My Company

+

+
+
- - endBody(); ?> -
- + endBody() ?> -endPage(); ?> +endPage() ?> diff --git a/apps/advanced/backend/views/site/error.php b/apps/advanced/backend/views/site/error.php new file mode 100644 index 0000000..1b7ce04 --- /dev/null +++ b/apps/advanced/backend/views/site/error.php @@ -0,0 +1,29 @@ +title = $name; +?> +
+ +

title) ?>

+ +
+ +
+ +

+ The above error occurred while the Web server was processing your request. +

+

+ Please contact us if you think this is a server error. Thank you. +

+ +
diff --git a/apps/advanced/backend/views/site/index.php b/apps/advanced/backend/views/site/index.php index 158b61c..bcb2278 100644 --- a/apps/advanced/backend/views/site/index.php +++ b/apps/advanced/backend/views/site/index.php @@ -1,47 +1,53 @@ title = 'Welcome'; +$this->title = 'My Yii Application'; ?> -
-

Welcome!

+
-

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus - commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

- Get started with Yii -
+
+

Congratulations!

-
+

You have successfully created your Yii-powered application.

- -
-
-

Heading

+

Get started with Yii

+
-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris - condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. - Donec sed odio dui.

+ -
-

Heading

+
+
+

Heading

-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris - condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. - Donec sed odio dui.

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu + fugiat nulla pariatur.

-

View details »

-
-
-

Heading

+

Yii Documentation »

+
+
+

Heading

-

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta - felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum - massa.

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu + fugiat nulla pariatur.

+ +

Yii Forum »

+
+
+

Heading

+ +

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu + fugiat nulla pariatur.

+ +

Yii Extensions »

+
+
-

View details »

- diff --git a/apps/advanced/backend/views/site/login.php b/apps/advanced/backend/views/site/login.php index f676b98..41973e5 100644 --- a/apps/advanced/backend/views/site/login.php +++ b/apps/advanced/backend/views/site/login.php @@ -3,22 +3,28 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; /** - * @var yii\base\View $this + * @var yii\web\View $this * @var yii\widgets\ActiveForm $form * @var app\models\LoginForm $model */ $this->title = 'Login'; $this->params['breadcrumbs'][] = $this->title; ?> -

title); ?>

+