Browse Source

Merge branch 'master' into elasticsearch

* master: (587 commits)
  fixed typo
  Fixes #1222: refactored jui/Widget, intorduced jui/Slider and jui/SliderInput
  Correct Nav.php comments/PHP doc to reflect BS3 dropdown support.
  Correct Nav.php comments/PHP doc to reflect BS3 dropdown support.
  Correct Nav.php comments/PHP doc to reflect BS3 dropdown support.
  Added example for dividers to bootstrap Nav
  Checkboxlist documentation fix
  Added "Using controller action to render errors"
  Fix doc
  Renamed DetailView attribute type to format
  encode email in Formatter
  Added default status code setting.
  "yii\swiftmailer\Mailer" transport setup has been advanced to support constructor arguments and plugins.
  fix rbac select statement
  Comments cleanup.
  Reverted closeButton
  Nomenclature and code realignment.
  better nginx config
  guide about using bootstrap less files
  Include Schema in new migrations by default
  ...

Conflicts:
	framework/composer.json
	tests/unit/data/config.php
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
8341a59717
  1. 3
      .gitignore
  2. 6
      .travis.yml
  3. 4
      LICENSE.md
  4. 4
      README.md
  5. 4
      apps/advanced/LICENSE.md
  6. 9
      apps/advanced/README.md
  7. 1
      apps/advanced/backend/assets/.gitkeep
  8. 13
      apps/advanced/backend/assets/AppAsset.php
  9. 45
      apps/advanced/backend/config/main.php
  10. 4
      apps/advanced/backend/config/params.php
  11. 45
      apps/advanced/backend/controllers/SiteController.php
  12. 48
      apps/advanced/backend/views/layouts/main.php
  13. 6
      apps/advanced/backend/views/site/error.php
  14. 2
      apps/advanced/backend/views/site/index.php
  15. 14
      apps/advanced/backend/views/site/login.php
  16. 21
      apps/advanced/backend/web/css/site.css
  17. 22
      apps/advanced/common/config/params.php
  18. 31
      apps/advanced/common/models/LoginForm.php
  19. 54
      apps/advanced/common/models/User.php
  20. 12
      apps/advanced/composer.json
  21. 28
      apps/advanced/console/config/main.php
  22. 4
      apps/advanced/console/config/params.php
  23. 4
      apps/advanced/console/migrations/m130524_201442_init.php
  24. 16
      apps/advanced/environments/dev/backend/config/main-local.php
  25. 4
      apps/advanced/environments/dev/backend/config/params-local.php
  26. 4
      apps/advanced/environments/dev/common/config/params-local.php
  27. 4
      apps/advanced/environments/dev/console/config/main-local.php
  28. 4
      apps/advanced/environments/dev/console/config/params-local.php
  29. 16
      apps/advanced/environments/dev/frontend/config/main-local.php
  30. 4
      apps/advanced/environments/dev/frontend/config/params-local.php
  31. 1
      apps/advanced/environments/dev/frontend/web/index.php
  32. 1
      apps/advanced/environments/dev/yii
  33. 40
      apps/advanced/environments/index.php
  34. 4
      apps/advanced/environments/prod/backend/config/main-local.php
  35. 4
      apps/advanced/environments/prod/backend/config/params-local.php
  36. 4
      apps/advanced/environments/prod/common/config/params-local.php
  37. 4
      apps/advanced/environments/prod/console/config/main-local.php
  38. 4
      apps/advanced/environments/prod/console/config/params-local.php
  39. 4
      apps/advanced/environments/prod/frontend/config/main-local.php
  40. 4
      apps/advanced/environments/prod/frontend/config/params-local.php
  41. 1
      apps/advanced/environments/prod/frontend/web/index.php
  42. 1
      apps/advanced/environments/prod/yii
  43. 14
      apps/advanced/frontend/assets/AppAsset.php
  44. 42
      apps/advanced/frontend/config/main.php
  45. 4
      apps/advanced/frontend/config/params.php
  46. 81
      apps/advanced/frontend/controllers/SiteController.php
  47. 28
      apps/advanced/frontend/models/ContactForm.php
  48. 8
      apps/advanced/frontend/views/emails/passwordResetToken.php
  49. 56
      apps/advanced/frontend/views/layouts/main.php
  50. 6
      apps/advanced/frontend/views/site/about.php
  51. 22
      apps/advanced/frontend/views/site/contact.php
  52. 6
      apps/advanced/frontend/views/site/error.php
  53. 2
      apps/advanced/frontend/views/site/index.php
  54. 16
      apps/advanced/frontend/views/site/login.php
  55. 10
      apps/advanced/frontend/views/site/requestPasswordResetToken.php
  56. 10
      apps/advanced/frontend/views/site/resetPassword.php
  57. 14
      apps/advanced/frontend/views/site/signup.php
  58. 21
      apps/advanced/frontend/web/css/site.css
  59. 64
      apps/advanced/frontend/widgets/Alert.php
  60. 12
      apps/advanced/init
  61. 46
      apps/advanced/requirements.php
  62. 4
      apps/basic/LICENSE.md
  63. 2
      apps/basic/README.md
  64. 14
      apps/basic/assets/AppAsset.php
  65. 1
      apps/basic/codeception.yml
  66. 13
      apps/basic/composer.json
  67. 33
      apps/basic/config/console.php
  68. 4
      apps/basic/config/params.php
  69. 44
      apps/basic/config/web.php
  70. 63
      apps/basic/controllers/SiteController.php
  71. 28
      apps/basic/models/ContactForm.php
  72. 31
      apps/basic/models/LoginForm.php
  73. 16
      apps/basic/models/User.php
  74. 46
      apps/basic/requirements.php
  75. 20
      apps/basic/tests/README.md
  76. 10
      apps/basic/tests/acceptance/ContactCept.php
  77. 10
      apps/basic/tests/acceptance/LoginCept.php
  78. 1355
      apps/basic/tests/acceptance/WebGuy.php
  79. 10
      apps/basic/tests/functional/ContactCept.php
  80. 10
      apps/basic/tests/functional/LoginCept.php
  81. 1359
      apps/basic/tests/functional/TestGuy.php
  82. 15
      apps/basic/tests/unit/CodeGuy.php
  83. 57
      apps/basic/views/layouts/main.php
  84. 6
      apps/basic/views/site/about.php
  85. 22
      apps/basic/views/site/contact.php
  86. 6
      apps/basic/views/site/error.php
  87. 2
      apps/basic/views/site/index.php
  88. 26
      apps/basic/views/site/login.php
  89. 21
      apps/basic/web/css/site.css
  90. 14
      apps/basic/web/index-test.php
  91. 1
      apps/basic/web/index.php
  92. 1
      apps/basic/yii
  93. 4
      apps/benchmark/LICENSE.md
  94. 2
      apps/benchmark/README.md
  95. 2
      apps/benchmark/composer.json
  96. 12
      apps/benchmark/index.php
  97. 4
      build/build
  98. 19
      build/controllers/ClassmapController.php
  99. 114
      build/controllers/LocaleController.php
  100. 67
      build/controllers/PhpDocController.php
  101. Some files were not shown because too many files have changed in this diff Show More

3
.gitignore vendored

@ -20,3 +20,6 @@ composer.phar
# Mac DS_Store Files
.DS_Store
# local phpunit config
/phpunit.xml

6
.travis.yml

@ -1,13 +1,9 @@
language: php
php:
- 5.3
- 5.4
- 5.5
env:
- CUBRID_VERSION=9.1.0
services:
- redis-server
- memcached
@ -23,7 +19,7 @@ before_script:
- tests/unit/data/travis/cubrid-setup.sh
script:
- phpunit --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata
- phpunit --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata,vendor
after_script:
- php vendor/bin/coveralls

4
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.
POSSIBILITY OF SUCH DAMAGE.

4
README.md

@ -33,7 +33,7 @@ DIRECTORY STRUCTURE
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
@ -42,7 +42,7 @@ DOCUMENTATION
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.
[Definitive Guide draft](docs/guide/index.md) is available. It's not complete yet but main parts are already OK.
HOW TO PARTICIPATE

4
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.
POSSIBILITY OF SUCH DAMAGE.

9
apps/advanced/README.md

@ -52,7 +52,7 @@ environments/ contains environment-based overrides
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.0.
In order for captcha to work you need either GD2 extension or ImageMagick PHP extension.
@ -76,6 +76,13 @@ php composer.phar create-project --stability=dev yiisoft/yii2-app-advanced yii-a
Note that in order to install some dependencies you must have `php_openssl` extension enabled.
After the application is installed, switch to the project folder and run the following command
to initialize the application:
~~~
./init (init on Windows)
~~~
### Install from an Archive File

1
apps/advanced/backend/assets/.gitkeep

@ -1 +0,0 @@
*

13
apps/advanced/frontend/config/AppAsset.php → apps/advanced/backend/assets/AppAsset.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace frontend\config;
namespace backend\assets;
use yii\web\AssetBundle;
@ -17,13 +17,10 @@ class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = array(
'css/site.css',
);
public $js = array(
);
public $depends = array(
public $css = ['css/site.css'];
public $js = [];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
);
];
}

45
apps/advanced/backend/config/main.php

@ -1,5 +1,5 @@
<?php
$rootDir = __DIR__ . '/../..';
$rootDir = dirname(dirname(__DIR__));
$params = array_merge(
require($rootDir . '/common/config/params.php'),
@ -8,35 +8,36 @@ $params = array_merge(
require(__DIR__ . '/params-local.php')
);
return array(
return [
'id' => '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(
'request' => array(
'modules' => [],
'extensions' => require($rootDir . '/vendor/yiisoft/extensions.php'),
'components' => [
'request' => [
'enableCsrfValidation' => true,
),
],
'db' => $params['components.db'],
'cache' => $params['components.cache'],
'user' => array(
'mail' => $params['components.mail'],
'user' => [
'identityClass' => 'common\models\User',
),
'log' => array(
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => array(
array(
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => array('error', 'warning'),
),
),
),
'errorHandler' => array(
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
),
),
],
],
'params' => $params,
);
];

4
apps/advanced/backend/config/params.php

@ -1,4 +1,4 @@
<?php
return array(
return [
'adminEmail' => 'admin@example.com',
);
];

45
apps/advanced/backend/controllers/SiteController.php

@ -10,32 +10,31 @@ class SiteController extends Controller
{
public function behaviors()
{
return array(
'access' => array(
return [
'access' => [
'class' => \yii\web\AccessControl::className(),
'rules' => array(
array(
'actions' => array('login'),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
'roles' => array('?'),
),
array(
'actions' => array('logout', 'index'),
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => array('@'),
),
),
),
);
'roles' => ['@'],
],
],
],
];
}
public function actions()
{
return array(
'error' => array(
return [
'error' => [
'class' => 'yii\web\ErrorAction',
),
);
],
];
}
public function actionIndex()
@ -45,13 +44,17 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
return $this->goHome();
return $this->goBack();
} else {
return $this->render('login', array(
return $this->render('login', [
'model' => $model,
));
]);
}
}

48
apps/advanced/backend/views/layouts/main.php

@ -1,60 +1,60 @@
<?php
use backend\config\AppAsset;
use backend\assets\AppAsset;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
/**
* @var $this \yii\base\View
* @var $content string
* @var \yii\web\View $this
* @var string $content
*/
AppAsset::register($this);
?>
<?php $this->beginPage(); ?>
<!DOCTYPE html>
<html lang="en">
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?php echo Yii::$app->charset; ?>"/>
<title><?php echo Html::encode($this->title); ?></title>
<meta charset="<?= Yii::$app->charset ?>"/>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head(); ?>
</head>
<body>
<?php $this->beginBody(); ?>
<?php
NavBar::begin(array(
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => array(
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
),
));
$menuItems = array(
array('label' => 'Home', 'url' => array('/site/index')),
);
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = array('label' => 'Login', 'url' => array('/site/login'));
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = array('label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => array('/site/logout'));
$menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => ['/site/logout']];
}
echo Nav::widget(array(
'options' => array('class' => 'navbar-nav pull-right'),
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
));
]);
NavBar::end();
?>
<div class="container">
<?php echo Breadcrumbs::widget(array(
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
)); ?>
<?php echo $content; ?>
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= $content ?>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; My Company <?php echo date('Y'); ?></p>
<p class="pull-right"><?php echo Yii::powered(); ?></p>
<p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>

6
apps/advanced/backend/views/site/error.php

@ -3,7 +3,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var string $name
* @var string $message
* @var Exception $exception
@ -13,10 +13,10 @@ $this->title = $name;
?>
<div class="site-error">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?php echo nl2br(Html::encode($message)); ?>
<?= nl2br(Html::encode($message)) ?>
</div>
<p>

2
apps/advanced/backend/views/site/index.php

@ -1,6 +1,6 @@
<?php
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'My Yii Application';
?>

14
apps/advanced/backend/views/site/login.php

@ -3,7 +3,7 @@ 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
*/
@ -11,18 +11,18 @@ $this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(array('id' => 'login-form')); ?>
<?php echo $form->field($model, 'username'); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox() ?>
<div class="form-group">
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

21
apps/advanced/backend/web/css/site.css

@ -17,3 +17,24 @@ body {
font-size: 21px;
padding: 14px 24px;
}
/* add sorting icons to gridview sort links */
a.asc:after, a.desc:after {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
padding-left: 5px;
}
a.asc:after { content: /*"\e113"*/"\e151"; }
a.desc:after { content: /*"\e114"*/"\e152"; }
.sort-numerical a.asc:after { content: "\e153"; }
.sort-numerical a.desc:after { content: "\e154"; }
.sort-ordinal a.asc:after { content: "\e155"; }
.sort-ordinal a.desc:after { content: "\e156"; }

22
apps/advanced/common/config/params.php

@ -1,22 +1,26 @@
<?php
Yii::setAlias('common', __DIR__ . '/../');
Yii::setAlias('frontend', __DIR__ . '/../../frontend');
Yii::setAlias('backend', __DIR__ . '/../../backend');
Yii::setAlias('common', realpath(__DIR__ . '/../'));
Yii::setAlias('frontend', realpath(__DIR__ . '/../../frontend'));
Yii::setAlias('backend', realpath(__DIR__ . '/../../backend'));
return array(
return [
'adminEmail' => 'admin@example.com',
'supportEmail' => 'support@example.com',
'components.cache' => array(
'components.cache' => [
'class' => 'yii\caching\FileCache',
),
],
'components.db' => array(
'components.mail' => [
'class' => 'yii\swiftmailer\Mailer',
],
'components.db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
);
],
];

31
apps/advanced/common/models/LoginForm.php

@ -14,19 +14,21 @@ class LoginForm extends Model
public $password;
public $rememberMe = true;
private $_user = false;
/**
* @return array the validation rules.
*/
public function rules()
{
return array(
return [
// username and password are both required
array('username, password', 'required'),
[['username', 'password'], 'required'],
// password is validated by validatePassword()
array('password', 'validatePassword'),
['password', 'validatePassword'],
// rememberMe must be a boolean value
array('rememberMe', 'boolean'),
);
['rememberMe', 'boolean'],
];
}
/**
@ -35,7 +37,7 @@ class LoginForm extends Model
*/
public function validatePassword()
{
$user = User::findByUsername($this->username);
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
}
@ -48,11 +50,22 @@ class LoginForm extends Model
public function login()
{
if ($this->validate()) {
$user = User::findByUsername($this->username);
Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0);
return true;
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0);
} else {
return false;
}
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
private function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
}

54
apps/advanced/common/models/User.php

@ -34,15 +34,15 @@ class User extends ActiveRecord implements IdentityInterface
public function behaviors()
{
return array(
'timestamp' => array(
return [
'timestamp' => [
'class' => 'yii\behaviors\AutoTimestamp',
'attributes' => array(
ActiveRecord::EVENT_BEFORE_INSERT => array('create_time', 'update_time'),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time',
),
),
);
],
],
];
}
/**
@ -64,7 +64,7 @@ class User extends ActiveRecord implements IdentityInterface
*/
public static function findByUsername($username)
{
return static::find(array('username' => $username, 'status' => static::STATUS_ACTIVE));
return static::find(['username' => $username, 'status' => static::STATUS_ACTIVE]);
}
/**
@ -103,29 +103,29 @@ class User extends ActiveRecord implements IdentityInterface
public function rules()
{
return array(
array('username', 'filter', 'filter' => 'trim'),
array('username', 'required'),
array('username', 'string', 'min' => 2, 'max' => 255),
array('email', 'filter', 'filter' => 'trim'),
array('email', 'required'),
array('email', 'email'),
array('email', 'unique', 'message' => 'This email address has already been taken.', 'on' => 'signup'),
array('email', 'exist', 'message' => 'There is no user with such email.', 'on' => 'requestPasswordResetToken'),
array('password', 'required'),
array('password', 'string', 'min' => 6),
);
return [
['username', 'filter', 'filter' => 'trim'],
['username', 'required'],
['username', 'string', 'min' => 2, 'max' => 255],
['email', 'filter', 'filter' => 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'unique', 'message' => 'This email address has already been taken.', 'on' => 'signup'],
['email', 'exist', 'message' => 'There is no user with such email.', 'on' => 'requestPasswordResetToken'],
['password', 'required'],
['password', 'string', 'min' => 6],
];
}
public function scenarios()
{
return array(
'signup' => array('username', 'email', 'password'),
'resetPassword' => array('password'),
'requestPasswordResetToken' => array('email'),
);
return [
'signup' => ['username', 'email', 'password'],
'resetPassword' => ['password'],
'requestPasswordResetToken' => ['email'],
];
}
public function beforeSave($insert)

12
apps/advanced/composer.json

@ -14,18 +14,20 @@
},
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0",
"php": ">=5.4.0",
"yiisoft/yii2": "dev-master",
"yiisoft/yii2-composer": "dev-master"
"yiisoft/yii2-swiftmailer": "dev-master",
"yiisoft/yii2-bootstrap": "dev-master",
"yiisoft/yii2-debug": "dev-master",
"yiisoft/yii2-gii": "dev-master"
},
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\InstallHandler::setPermissions",
"./init"
"yii\\composer\\Installer::setPermission"
]
},
"extra": {
"yii-install-writable": [
"writable": [
"backend/runtime",
"backend/web/assets",

28
apps/advanced/console/config/main.php

@ -8,24 +8,26 @@ $params = array_merge(
require(__DIR__ . '/params-local.php')
);
return array(
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'controllerNamespace' => 'console\controllers',
'modules' => array(
),
'components' => array(
'modules' => [
],
'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'),
'components' => [
'db' => $params['components.db'],
'cache' => $params['components.cache'],
'log' => array(
'targets' => array(
array(
'mail' => $params['components.mail'],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => array('error', 'warning'),
),
),
),
),
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params,
);
];

4
apps/advanced/console/config/params.php

@ -1,4 +1,4 @@
<?php
return array(
return [
'adminEmail' => 'admin@example.com',
);
];

4
apps/advanced/console/migrations/m130524_201442_init.php

@ -9,7 +9,7 @@ class m130524_201442_init extends \yii\db\Migration
// MySQL-specific table options. Adjust if you plan working with another DBMS
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
$this->createTable('tbl_user', array(
$this->createTable('tbl_user', [
'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING.' NOT NULL',
'auth_key' => Schema::TYPE_STRING.'(32) NOT NULL',
@ -21,7 +21,7 @@ class m130524_201442_init extends \yii\db\Migration
'status' => 'tinyint NOT NULL DEFAULT 10',
'create_time' => Schema::TYPE_INTEGER.' NOT NULL',
'update_time' => Schema::TYPE_INTEGER.' NOT NULL',
), $tableOptions);
], $tableOptions);
}
public function down()

16
apps/advanced/environments/dev/backend/config/main-local.php

@ -1,11 +1,11 @@
<?php
return array(
'preload' => array(
return [
'preload' => [
//'debug',
),
'modules' => array(
// 'debug' => array(
],
'modules' => [
// 'debug' => [
// 'class' => 'yii\debug\Module',
// ),
),
);
// ],
],
];

4
apps/advanced/environments/dev/backend/config/params-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/dev/common/config/params-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/dev/console/config/main-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/dev/console/config/params-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

16
apps/advanced/environments/dev/frontend/config/main-local.php

@ -1,11 +1,11 @@
<?php
return array(
'preload' => array(
return [
'preload' => [
//'debug',
),
'modules' => array(
// 'debug' => array(
],
'modules' => [
// 'debug' => [
// 'class' => 'yii\debug\Module',
// ),
),
);
// ],
],
];

4
apps/advanced/environments/dev/frontend/config/params-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

1
apps/advanced/environments/dev/frontend/web/index.php

@ -4,7 +4,6 @@ defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
Yii::importNamespaces(require(__DIR__ . '/../../vendor/composer/autoload_namespaces.php'));
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),

1
apps/advanced/environments/dev/yii

@ -16,7 +16,6 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
Yii::importNamespaces(require(__DIR__ . '/vendor/composer/autoload_namespaces.php'));
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/console/config/main.php'),

40
apps/advanced/environments/index.php

@ -6,33 +6,33 @@
* format:
*
* ```php
* return array(
* 'environment name' => array(
* return [
* 'environment name' => [
* 'path' => 'directory storing the local files',
* 'writable' => array(
* 'writable' => [
* // list of directories that should be set writable
* ),
* ),
* );
* ],
* ],
* ];
* ```
*/
return array(
'Development' => array(
return [
'Development' => [
'path' => 'dev',
'writable' => array(
'writable' => [
// handled by composer.json already
),
'executable' => array(
],
'executable' => [
'yii',
),
),
'Production' => array(
],
],
'Production' => [
'path' => 'prod',
'writable' => array(
'writable' => [
// handled by composer.json already
),
'executable' => array(
],
'executable' => [
'yii',
),
),
);
],
],
];

4
apps/advanced/environments/prod/backend/config/main-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/prod/backend/config/params-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/prod/common/config/params-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/prod/console/config/main-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/prod/console/config/params-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/prod/frontend/config/main-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

4
apps/advanced/environments/prod/frontend/config/params-local.php

@ -1,3 +1,3 @@
<?php
return array(
);
return [
];

1
apps/advanced/environments/prod/frontend/web/index.php

@ -4,7 +4,6 @@ defined('YII_ENV') or define('YII_ENV', 'prod');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/yii/Yii.php');
Yii::importNamespaces(require(__DIR__ . '/../../vendor/composer/autoload_namespaces.php'));
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/main.php'),

1
apps/advanced/environments/prod/yii

@ -16,7 +16,6 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
Yii::importNamespaces(require(__DIR__ . '/vendor/composer/autoload_namespaces.php'));
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/console/config/main.php'),

14
apps/basic/config/AppAsset.php → apps/advanced/frontend/assets/AppAsset.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace app\config;
namespace frontend\assets;
use yii\web\AssetBundle;
@ -17,13 +17,13 @@ class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = array(
public $css = [
'css/site.css',
);
public $js = array(
);
public $depends = array(
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
);
];
}

42
apps/advanced/frontend/config/main.php

@ -8,35 +8,37 @@ $params = array_merge(
require(__DIR__ . '/params-local.php')
);
return array(
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'vendorPath' => $rootDir . '/vendor',
'controllerNamespace' => 'frontend\controllers',
'modules' => array(
'modules' => [
'gii' => 'yii\gii\Module'
),
'components' => array(
'request' => array(
],
'extensions' => require($rootDir . '/vendor/yiisoft/extensions.php'),
'components' => [
'request' => [
'enableCsrfValidation' => true,
),
],
'db' => $params['components.db'],
'cache' => $params['components.cache'],
'user' => array(
'mail' => $params['components.mail'],
'user' => [
'identityClass' => 'common\models\User',
),
'log' => array(
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => array(
array(
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => array('error', 'warning'),
),
),
),
'errorHandler' => array(
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
),
),
],
],
'params' => $params,
);
];

4
apps/advanced/frontend/config/params.php

@ -1,4 +1,4 @@
<?php
return array(
return [
'adminEmail' => 'admin@example.com',
);
];

81
apps/advanced/frontend/controllers/SiteController.php

@ -14,37 +14,37 @@ class SiteController extends Controller
{
public function behaviors()
{
return array(
'access' => array(
return [
'access' => [
'class' => \yii\web\AccessControl::className(),
'only' => array('login', 'logout', 'signup'),
'rules' => array(
array(
'actions' => array('login', 'signup'),
'only' => ['logout', 'signup'],
'rules' => [
[
'actions' => ['signup'],
'allow' => true,
'roles' => array('?'),
),
array(
'actions' => array('logout'),
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => array('@'),
),
),
),
);
'roles' => ['@'],
],
],
],
];
}
public function actions()
{
return array(
'error' => array(
return [
'error' => [
'class' => 'yii\web\ErrorAction',
),
'captcha' => array(
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
),
);
],
];
}
public function actionIndex()
@ -54,13 +54,17 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
return $this->goHome();
return $this->goBack();
} else {
return $this->render('login', array(
return $this->render('login', [
'model' => $model,
));
]);
}
}
@ -77,9 +81,9 @@ class SiteController extends Controller
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
return $this->refresh();
} else {
return $this->render('contact', array(
return $this->render('contact', [
'model' => $model,
));
]);
}
}
@ -98,9 +102,9 @@ class SiteController extends Controller
}
}
return $this->render('signup', array(
return $this->render('signup', [
'model' => $model,
));
]);
}
public function actionRequestPasswordReset()
@ -115,17 +119,17 @@ class SiteController extends Controller
Yii::$app->getSession()->setFlash('error', 'There was an error sending email.');
}
}
return $this->render('requestPasswordResetToken', array(
return $this->render('requestPasswordResetToken', [
'model' => $model,
));
]);
}
public function actionResetPassword($token)
{
$model = User::find(array(
$model = User::find([
'password_reset_token' => $token,
'status' => User::STATUS_ACTIVE,
));
]);
if (!$model) {
throw new HttpException(400, 'Wrong password reset token.');
@ -137,17 +141,17 @@ class SiteController extends Controller
return $this->goHome();
}
return $this->render('resetPassword', array(
return $this->render('resetPassword', [
'model' => $model,
));
]);
}
private function sendPasswordResetEmail($email)
{
$user = User::find(array(
$user = User::find([
'status' => User::STATUS_ACTIVE,
'email' => $email,
));
]);
if (!$user) {
return false;
@ -155,12 +159,13 @@ class SiteController extends Controller
$user->password_reset_token = Security::generateRandomKey();
if ($user->save(false)) {
// todo: refactor it with mail component. pay attention to the arrangement of mail view files
$fromEmail = \Yii::$app->params['supportEmail'];
$name = '=?UTF-8?B?' . base64_encode(\Yii::$app->name . ' robot') . '?=';
$subject = '=?UTF-8?B?' . base64_encode('Password reset for ' . \Yii::$app->name) . '?=';
$body = $this->renderPartial('/emails/passwordResetToken', array(
$body = $this->renderPartial('/emails/passwordResetToken', [
'user' => $user,
));
]);
$headers = "From: $name <{$fromEmail}>\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8";

28
apps/advanced/frontend/models/ContactForm.php

@ -2,6 +2,7 @@
namespace frontend\models;
use Yii;
use yii\base\Model;
/**
@ -20,14 +21,14 @@ class ContactForm extends Model
*/
public function rules()
{
return array(
return [
// name, email, subject and body are required
array('name, email, subject, body', 'required'),
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
array('email', 'email'),
['email', 'email'],
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha'),
);
['verifyCode', 'captcha'],
];
}
/**
@ -35,9 +36,9 @@ class ContactForm extends Model
*/
public function attributeLabels()
{
return array(
return [
'verifyCode' => 'Verification Code',
);
];
}
/**
@ -48,13 +49,12 @@ class ContactForm extends Model
public function contact($email)
{
if ($this->validate()) {
$name = '=?UTF-8?B?' . base64_encode($this->name) . '?=';
$subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?=';
$headers = "From: $name <{$this->email}>\r\n" .
"Reply-To: {$this->email}\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8";
mail($email, $subject, $this->body, $headers);
Yii::$app->mail->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
return true;
} else {
return false;

8
apps/advanced/frontend/views/emails/passwordResetToken.php

@ -2,15 +2,15 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var common\models\User $user;
*/
$resetLink = Yii::$app->urlManager->createAbsoluteUrl('site/reset-password', array('token' => $user->password_reset_token));
$resetLink = Yii::$app->urlManager->createAbsoluteUrl('site/reset-password', ['token' => $user->password_reset_token]);
?>
Hello <?php echo Html::encode($user->username)?>,
Hello <?= Html::encode($user->username) ?>,
Follow the link below to reset your password:
<?php echo Html::a(Html::encode($resetLink), $resetLink)?>
<?= Html::a(Html::encode($resetLink), $resetLink) ?>

56
apps/advanced/frontend/views/layouts/main.php

@ -1,65 +1,65 @@
<?php
use frontend\config\AppAsset;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use frontend\widgets\Alert;
/**
* @var $this \yii\base\View
* @var $content string
* @var \yii\web\View $this
* @var string $content
*/
AppAsset::register($this);
?>
<?php $this->beginPage(); ?>
<!DOCTYPE html>
<html lang="en">
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?php echo Yii::$app->charset; ?>"/>
<title><?php echo Html::encode($this->title); ?></title>
<meta charset="<?= Yii::$app->charset ?>"/>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head(); ?>
</head>
<body>
<?php $this->beginBody(); ?>
<?php
NavBar::begin(array(
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => array(
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
),
));
$menuItems = array(
array('label' => 'Home', 'url' => array('/site/index')),
array('label' => 'About', 'url' => array('/site/about')),
array('label' => 'Contact', 'url' => array('/site/contact')),
);
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = array('label' => 'Signup', 'url' => array('/site/signup'));
$menuItems[] = array('label' => 'Login', 'url' => array('/site/login'));
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = array('label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => array('/site/logout'));
$menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => ['/site/logout']];
}
echo Nav::widget(array(
'options' => array('class' => 'navbar-nav pull-right'),
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
));
]);
NavBar::end();
?>
<div class="container">
<?php echo Breadcrumbs::widget(array(
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
)); ?>
<?php echo Alert::widget()?>
<?php echo $content; ?>
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; My Company <?php echo date('Y'); ?></p>
<p class="pull-right"><?php echo Yii::powered(); ?></p>
<p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>

6
apps/advanced/frontend/views/site/about.php

@ -2,15 +2,15 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>This is the About page. You may modify the following file to customize its content:</p>
<code><?php echo __FILE__; ?></code>
<code><?= __FILE__ ?></code>
</div>

22
apps/advanced/frontend/views/site/contact.php

@ -4,7 +4,7 @@ use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\ContactForm $model
*/
@ -12,7 +12,7 @@ $this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-contact">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
@ -20,17 +20,17 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(array('id' => 'contact-form')); ?>
<?php echo $form->field($model, 'name'); ?>
<?php echo $form->field($model, 'email'); ?>
<?php echo $form->field($model, 'subject'); ?>
<?php echo $form->field($model, 'body')->textArea(array('rows' => 6)); ?>
<?php echo $form->field($model, 'verifyCode')->widget(Captcha::className(), array(
'options' => array('class' => 'form-control'),
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'options' => ['class' => 'form-control'],
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
)); ?>
]) ?>
<div class="form-group">
<?php echo Html::submitButton('Submit', array('class' => 'btn btn-primary')); ?>
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

6
apps/advanced/frontend/views/site/error.php

@ -3,7 +3,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var string $name
* @var string $message
* @var Exception $exception
@ -13,10 +13,10 @@ $this->title = $name;
?>
<div class="site-error">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?php echo nl2br(Html::encode($message)); ?>
<?= nl2br(Html::encode($message)) ?>
</div>
<p>

2
apps/advanced/frontend/views/site/index.php

@ -1,6 +1,6 @@
<?php
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'My Yii Application';
?>

16
apps/advanced/frontend/views/site/login.php

@ -3,7 +3,7 @@ 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
*/
@ -11,21 +11,21 @@ $this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(array('id' => 'login-form')); ?>
<?php echo $form->field($model, 'username'); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox() ?>
<div style="color:#999;margin:1em 0">
If you forgot your password you can <?php echo Html::a('reset it', array('site/request-password-reset'))?>.
If you forgot your password you can <?= Html::a('reset it', ['site/request-password-reset']) ?>.
</div>
<div class="form-group">
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

10
apps/advanced/frontend/views/site/requestPasswordResetToken.php

@ -3,7 +3,7 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/
@ -11,16 +11,16 @@ $this->title = 'Request password reset';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-request-password-reset">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out your email. A link to reset password will be sent there.</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(array('id' => 'request-password-reset-form')); ?>
<?php echo $form->field($model, 'email'); ?>
<?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?>
<?= $form->field($model, 'email') ?>
<div class="form-group">
<?php echo Html::submitButton('Send', array('class' => 'btn btn-primary')); ?>
<?= Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

10
apps/advanced/frontend/views/site/resetPassword.php

@ -3,7 +3,7 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/
@ -11,16 +11,16 @@ $this->title = 'Reset password';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-reset-password">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>Please choose your new password:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(array('id' => 'reset-password-form')); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<?php $form = ActiveForm::begin(['id' => 'reset-password-form']); ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="form-group">
<?php echo Html::submitButton('Save', array('class' => 'btn btn-primary')); ?>
<?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

14
apps/advanced/frontend/views/site/signup.php

@ -3,7 +3,7 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var common\models\User $model
*/
@ -11,18 +11,18 @@ $this->title = 'Signup';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-signup">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to signup:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(array('id' => 'form-signup')); ?>
<?php echo $form->field($model, 'username'); ?>
<?php echo $form->field($model, 'email'); ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<?php $form = ActiveForm::begin(['id' => 'form-signup']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="form-group">
<?php echo Html::submitButton('Signup', array('class' => 'btn btn-primary')); ?>
<?= Html::submitButton('Signup', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

21
apps/advanced/frontend/web/css/site.css

@ -17,3 +17,24 @@ body {
font-size: 21px;
padding: 14px 24px;
}
/* add sorting icons to gridview sort links */
a.asc:after, a.desc:after {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
padding-left: 5px;
}
a.asc:after { content: /*"\e113"*/"\e151"; }
a.desc:after { content: /*"\e114"*/"\e152"; }
.sort-numerical a.asc:after { content: "\e153"; }
.sort-numerical a.desc:after { content: "\e154"; }
.sort-ordinal a.asc:after { content: "\e155"; }
.sort-ordinal a.desc:after { content: "\e156"; }

64
apps/advanced/frontend/widgets/Alert.php

@ -7,42 +7,60 @@
namespace frontend\widgets;
use yii\helpers\Html;
/**
* Alert widget renders a message from session flash. You can set message as following:
* Alert widget renders a message from session flash. All flash messages are displayed
* in the sequence they were assigned using setFlash. You can set message as following:
*
* - \Yii::$app->getSession()->setFlash('error', 'This is the message');
* - \Yii::$app->getSession()->setFlash('success', 'This is the message');
* - \Yii::$app->getSession()->setFlash('info', 'This is the message');
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @author Alexander Makarov <sam@rmcerative.ru>
*/
class Alert extends \yii\bootstrap\Alert
class Alert extends \yii\bootstrap\Widget
{
private $_doNotRender = false;
/**
* @var array the alert types configuration for the flash messages.
* This array is setup as $key => $value, where:
* - $key is the name of the session flash variable
* - $value is the bootstrap alert type (i.e. danger, success, info, warning)
*/
public $alertTypes = [
'error' => 'danger',
'danger' => 'danger',
'success' => 'success',
'info' => 'info',
'warning' => 'warning'
];
/**
* @var array the options for rendering the close button tag.
*/
public $closeButton = [];
public function init()
{
if ($this->body = \Yii::$app->getSession()->getFlash('error', null, true)) {
Html::addCssClass($this->options, 'alert-danger');
} elseif ($this->body = \Yii::$app->getSession()->getFlash('success', null, true)) {
Html::addCssClass($this->options, 'alert-success');
} elseif ($this->body = \Yii::$app->getSession()->getFlash('info', null, true)) {
Html::addCssClass($this->options, 'alert-info');
} elseif ($this->body = \Yii::$app->getSession()->getFlash('warning', null, true)) {
Html::addCssClass($this->options, 'alert-warning');
} else {
$this->_doNotRender = true;
return;
}
parent::init();
}
public function run()
{
if (!$this->_doNotRender) {
parent::run();
$session = \Yii::$app->getSession();
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $message) {
/* initialize css class for each alert box */
$this->options['class'] = 'alert-' . $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type;
echo \yii\bootstrap\Alert::widget([
'body' => $message,
'closeButton' => $this->closeButton,
'options' => $this->options
]);
$session->removeFlash($type);
}
}
}

12
apps/advanced/init

@ -18,10 +18,10 @@ if (empty($params['env'])) {
if (!ctype_digit($answer) || !in_array($answer, range(0, count($envs) - 1))) {
echo "\n Quit initialization.\n";
exit(1);
exit(0);
}
if(isset($envNames[$answer])) {
if (isset($envNames[$answer])) {
$envName = $envNames[$answer];
}
}
@ -42,7 +42,7 @@ if (empty($params['env'])) {
$answer = trim(fgets(STDIN));
if (strncasecmp($answer, 'y', 1)) {
echo "\n Quit initialization.\n";
exit(1);
exit(0);
}
}
@ -73,7 +73,7 @@ echo "\n ... initialization completed.\n\n";
function getFileList($root, $basePath = '')
{
$files = array();
$files = [];
$handle = opendir($root);
while (($path = readdir($handle)) !== false) {
if ($path === '.svn' || $path === '.' || $path === '..') {
@ -135,13 +135,13 @@ function copyFile($root, $source, $target, &$all)
function getParams()
{
$rawParams = array();
$rawParams = [];
if (isset($_SERVER['argv'])) {
$rawParams = $_SERVER['argv'];
array_shift($rawParams);
}
$params = array();
$params = [];
foreach ($rawParams as $param) {
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
$name = $matches[1];

46
apps/advanced/requirements.php

@ -26,78 +26,78 @@ $requirementsChecker = new YiiRequirementChecker();
/**
* Adjust requirements according to your application specifics.
*/
$requirements = array(
$requirements = [
// Database :
array(
[
'name' => 'PDO extension',
'mandatory' => true,
'condition' => extension_loaded('pdo'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
),
array(
],
[
'name' => 'PDO SQLite extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_sqlite'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for SQLite database.',
),
array(
],
[
'name' => 'PDO MySQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_mysql'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for MySQL database.',
),
],
// Cache :
array(
[
'name' => 'Memcache extension',
'mandatory' => false,
'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>',
'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc/api/CMemCache#useMemcached-detail">CMemCache::useMemcached</a> to <code>true</code>.' : ''
),
array(
],
[
'name' => 'APC extension',
'mandatory' => false,
'condition' => extension_loaded('apc') || extension_loaded('apc'),
'condition' => extension_loaded('apc'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>',
),
],
// Additional PHP extensions :
array(
[
'name' => 'Mcrypt extension',
'mandatory' => false,
'condition' => extension_loaded('mcrypt'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
'memo' => 'Required by encrypt and decrypt methods.'
),
],
// PHP ini :
'phpSafeMode' => array(
'phpSafeMode' => [
'name' => 'PHP safe mode',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"),
'by' => 'File uploading and console command execution',
'memo' => '"safe_mode" should be disabled at php.ini',
),
'phpExposePhp' => array(
],
'phpExposePhp' => [
'name' => 'Expose PHP',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
'by' => 'Security reasons',
'memo' => '"expose_php" should be disabled at php.ini',
),
'phpAllowUrlInclude' => array(
],
'phpAllowUrlInclude' => [
'name' => 'PHP allow url include',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
'by' => 'Security reasons',
'memo' => '"allow_url_include" should be disabled at php.ini',
),
'phpSmtp' => array(
],
'phpSmtp' => [
'name' => 'PHP mail SMTP',
'mandatory' => false,
'condition' => strlen(ini_get('SMTP'))>0,
'by' => 'Email sending',
'memo' => 'PHP mail SMTP server required',
),
);
],
];
$requirementsChecker->checkYii()->check($requirements)->render();

4
apps/basic/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.
POSSIBILITY OF SUCH DAMAGE.

2
apps/basic/README.md

@ -31,7 +31,7 @@ DIRECTORY STRUCTURE
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.0.
In order for captcha to work you need either GD2 extension or ImageMagick PHP extension.

14
apps/advanced/backend/config/AppAsset.php → apps/basic/assets/AppAsset.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace backend\config;
namespace app\assets;
use yii\web\AssetBundle;
@ -17,13 +17,13 @@ class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = array(
public $css = [
'css/site.css',
);
public $js = array(
);
public $depends = array(
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
);
];
}

1
apps/basic/codeception.yml

@ -6,7 +6,6 @@ paths:
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
modules:

13
apps/basic/composer.json

@ -14,21 +14,24 @@
},
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0",
"php": ">=5.4.0",
"yiisoft/yii2": "dev-master",
"yiisoft/yii2-composer": "dev-master"
"yiisoft/yii2-swiftmailer": "dev-master",
"yiisoft/yii2-bootstrap": "dev-master",
"yiisoft/yii2-debug": "dev-master",
"yiisoft/yii2-gii": "dev-master"
},
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\InstallHandler::setPermissions"
"yii\\composer\\Installer::setPermission"
]
},
"extra": {
"yii-install-writable": [
"writable": [
"runtime",
"web/assets"
],
"yii-install-executable": [
"executable": [
"yii"
]
}

33
apps/basic/config/console.php

@ -1,25 +1,24 @@
<?php
$params = require(__DIR__ . '/params.php');
return array(
'id' => 'bootstrap-console',
return [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'preload' => array('log'),
'preload' => ['log'],
'controllerPath' => dirname(__DIR__) . '/commands',
'controllerNamespace' => 'app\commands',
'modules' => array(
),
'components' => array(
'cache' => array(
'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'),
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
),
'log' => array(
'targets' => array(
array(
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => array('error', 'warning'),
),
),
),
),
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params,
);
];

4
apps/basic/config/params.php

@ -1,5 +1,5 @@
<?php
return array(
return [
'adminEmail' => 'admin@example.com',
);
];

44
apps/basic/config/web.php

@ -1,33 +1,37 @@
<?php
$params = require(__DIR__ . '/params.php');
$config = array(
'id' => 'bootstrap',
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'components' => array(
'request' => array(
'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'),
'components' => [
'request' => [
'enableCsrfValidation' => true,
),
'cache' => array(
],
'cache' => [
'class' => 'yii\caching\FileCache',
),
'user' => array(
],
'user' => [
'identityClass' => 'app\models\User',
),
'errorHandler' => array(
],
'errorHandler' => [
'errorAction' => 'site/error',
),
'log' => array(
],
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => array(
array(
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => array('error', 'warning'),
),
),
),
),
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params,
);
];
if (YII_ENV_DEV) {
$config['preload'][] = 'debug';

63
apps/basic/controllers/SiteController.php

@ -13,43 +13,38 @@ class SiteController extends Controller
{
public function behaviors()
{
return array(
'access' => array(
return [
'access' => [
'class' => AccessControl::className(),
'only' => array('login', 'logout'),
'rules' => array(
array(
'actions' => array('login'),
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => array('?'),
),
array(
'actions' => array('logout'),
'allow' => true,
'roles' => array('@'),
),
),
),
'verbs' => array(
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => array(
'logout' => array('post'),
),
),
);
'actions' => [
'logout' => ['post'],
],
],
];
}
public function actions()
{
return array(
'error' => array(
return [
'error' => [
'class' => 'yii\web\ErrorAction',
),
'captcha' => array(
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
),
);
],
];
}
public function actionIndex()
@ -59,13 +54,17 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
return $this->goHome();
return $this->goBack();
} else {
return $this->render('login', array(
return $this->render('login', [
'model' => $model,
));
]);
}
}
@ -82,9 +81,9 @@ class SiteController extends Controller
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
} else {
return $this->render('contact', array(
return $this->render('contact', [
'model' => $model,
));
]);
}
}

28
apps/basic/models/ContactForm.php

@ -2,6 +2,7 @@
namespace app\models;
use Yii;
use yii\base\Model;
/**
@ -20,14 +21,14 @@ class ContactForm extends Model
*/
public function rules()
{
return array(
return [
// name, email, subject and body are required
array('name, email, subject, body', 'required'),
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
array('email', 'email'),
['email', 'email'],
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha'),
);
['verifyCode', 'captcha'],
];
}
/**
@ -35,9 +36,9 @@ class ContactForm extends Model
*/
public function attributeLabels()
{
return array(
return [
'verifyCode' => 'Verification Code',
);
];
}
/**
@ -48,13 +49,12 @@ class ContactForm extends Model
public function contact($email)
{
if ($this->validate()) {
$name = '=?UTF-8?B?' . base64_encode($this->name) . '?=';
$subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?=';
$headers = "From: $name <{$this->email}>\r\n" .
"Reply-To: {$this->email}\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8";
mail($email, $subject, $this->body, $headers);
Yii::$app->mail->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
return true;
} else {
return false;

31
apps/basic/models/LoginForm.php

@ -14,19 +14,21 @@ class LoginForm extends Model
public $password;
public $rememberMe = true;
private $_user = false;
/**
* @return array the validation rules.
*/
public function rules()
{
return array(
return [
// username and password are both required
array('username, password', 'required'),
[['username', 'password'], 'required'],
// password is validated by validatePassword()
array('password', 'validatePassword'),
['password', 'validatePassword'],
// rememberMe must be a boolean value
array('rememberMe', 'boolean'),
);
['rememberMe', 'boolean'],
];
}
/**
@ -35,7 +37,7 @@ class LoginForm extends Model
*/
public function validatePassword()
{
$user = User::findByUsername($this->username);
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
}
@ -48,11 +50,22 @@ class LoginForm extends Model
public function login()
{
if ($this->validate()) {
$user = User::findByUsername($this->username);
Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0);
return true;
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0);
} else {
return false;
}
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
private function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
}

16
apps/basic/models/User.php

@ -9,31 +9,31 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface
public $password;
public $authKey;
private static $users = array(
'100' => array(
private static $users = [
'100' => [
'id' => '100',
'username' => 'admin',
'password' => 'admin',
'authKey' => 'test100key',
),
'101' => array(
],
'101' => [
'id' => '101',
'username' => 'demo',
'password' => 'demo',
'authKey' => 'test101key',
),
);
],
];
public static function findIdentity($id)
{
return isset(self::$users[$id]) ? new self(self::$users[$id]) : null;
return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;
}
public static function findByUsername($username)
{
foreach (self::$users as $user) {
if (strcasecmp($user['username'], $username) === 0) {
return new self($user);
return new static($user);
}
}
return null;

46
apps/basic/requirements.php

@ -26,78 +26,78 @@ $requirementsChecker = new YiiRequirementChecker();
/**
* Adjust requirements according to your application specifics.
*/
$requirements = array(
$requirements = [
// Database :
array(
[
'name' => 'PDO extension',
'mandatory' => true,
'condition' => extension_loaded('pdo'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
),
array(
],
[
'name' => 'PDO SQLite extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_sqlite'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for SQLite database.',
),
array(
],
[
'name' => 'PDO MySQL extension',
'mandatory' => false,
'condition' => extension_loaded('pdo_mysql'),
'by' => 'All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>',
'memo' => 'Required for MySQL database.',
),
],
// Cache :
array(
[
'name' => 'Memcache extension',
'mandatory' => false,
'condition' => extension_loaded('memcache') || extension_loaded('memcached'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>',
'memo' => extension_loaded('memcached') ? 'To use memcached set <a href="http://www.yiiframework.com/doc/api/CMemCache#useMemcached-detail">CMemCache::useMemcached</a> to <code>true</code>.' : ''
),
array(
],
[
'name' => 'APC extension',
'mandatory' => false,
'condition' => extension_loaded('apc') || extension_loaded('apc'),
'condition' => extension_loaded('apc'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>',
),
],
// Additional PHP extensions :
array(
[
'name' => 'Mcrypt extension',
'mandatory' => false,
'condition' => extension_loaded('mcrypt'),
'by' => '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
'memo' => 'Required by encrypt and decrypt methods.'
),
],
// PHP ini :
'phpSafeMode' => array(
'phpSafeMode' => [
'name' => 'PHP safe mode',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("safe_mode"),
'by' => 'File uploading and console command execution',
'memo' => '"safe_mode" should be disabled at php.ini',
),
'phpExposePhp' => array(
],
'phpExposePhp' => [
'name' => 'Expose PHP',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("expose_php"),
'by' => 'Security reasons',
'memo' => '"expose_php" should be disabled at php.ini',
),
'phpAllowUrlInclude' => array(
],
'phpAllowUrlInclude' => [
'name' => 'PHP allow url include',
'mandatory' => false,
'condition' => $requirementsChecker->checkPhpIniOff("allow_url_include"),
'by' => 'Security reasons',
'memo' => '"allow_url_include" should be disabled at php.ini',
),
'phpSmtp' => array(
],
'phpSmtp' => [
'name' => 'PHP mail SMTP',
'mandatory' => false,
'condition' => strlen(ini_get('SMTP'))>0,
'by' => 'Email sending',
'memo' => 'PHP mail SMTP server required',
),
);
],
];
$requirementsChecker->checkYii()->check($requirements)->render();

20
apps/basic/tests/README.md

@ -0,0 +1,20 @@
This folder contains various tests for the basic application.
These tests are developed with [Codeception PHP Testing Framework](http://codeception.com/).
To run the tests, follow these steps:
1. [Install Codeception](http://codeception.com/quickstart) if you do not have it yet.
2. Create test configuration files based on your environment:
- Copy `acceptance.suite.dist.yml` to `acceptance.suite.yml` and customize it;
- Copy `functional.suite.dist.yml` to `functional.suite.yml` and customize it;
- Copy `unit.suite.dist.yml` to `unit.suite.yml` and customize it.
3. Switch to the parent folder and run tests:
```
cd ..
php codecept.phar build // rebuild test scripts, only need to be run once
php codecept.phar run // run all available tests
```
Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for
more details about writing acceptance, functional and unit tests.

10
apps/basic/tests/acceptance/ContactCept.php

@ -4,7 +4,7 @@ $I->wantTo('ensure that contact works');
$I->amOnPage('?r=site/contact');
$I->see('Contact', 'h1');
$I->submitForm('#contact-form', array());
$I->submitForm('#contact-form', []);
$I->see('Contact', 'h1');
$I->see('Name cannot be blank');
$I->see('Email cannot be blank');
@ -12,25 +12,25 @@ $I->see('Subject cannot be blank');
$I->see('Body cannot be blank');
$I->see('The verification code is incorrect');
$I->submitForm('#contact-form', array(
$I->submitForm('#contact-form', [
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester.email',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
));
]);
$I->dontSee('Name cannot be blank', '.help-inline');
$I->see('Email is not a valid email address.');
$I->dontSee('Subject cannot be blank', '.help-inline');
$I->dontSee('Body cannot be blank', '.help-inline');
$I->dontSee('The verification code is incorrect', '.help-inline');
$I->submitForm('#contact-form', array(
$I->submitForm('#contact-form', [
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester@example.com',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
));
]);
$I->dontSeeElement('#contact-form');
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');

10
apps/basic/tests/acceptance/LoginCept.php

@ -4,20 +4,20 @@ $I->wantTo('ensure that login works');
$I->amOnPage('?r=site/login');
$I->see('Login', 'h1');
$I->submitForm('#login-form', array());
$I->submitForm('#login-form', []);
$I->dontSee('Logout (admin)');
$I->see('Username cannot be blank');
$I->see('Password cannot be blank');
$I->submitForm('#login-form', array(
$I->submitForm('#login-form', [
'LoginForm[username]' => 'admin',
'LoginForm[password]' => 'wrong',
));
]);
$I->dontSee('Logout (admin)');
$I->see('Incorrect username or password');
$I->submitForm('#login-form', array(
$I->submitForm('#login-form', [
'LoginForm[username]' => 'admin',
'LoginForm[password]' => 'admin',
));
]);
$I->see('Logout (admin)');

1355
apps/basic/tests/acceptance/WebGuy.php

File diff suppressed because it is too large Load Diff

10
apps/basic/tests/functional/ContactCept.php

@ -4,7 +4,7 @@ $I->wantTo('ensure that contact works');
$I->amOnPage('?r=site/contact');
$I->see('Contact', 'h1');
$I->submitForm('#contact-form', array());
$I->submitForm('#contact-form', []);
$I->see('Contact', 'h1');
$I->see('Name cannot be blank');
$I->see('Email cannot be blank');
@ -12,25 +12,25 @@ $I->see('Subject cannot be blank');
$I->see('Body cannot be blank');
$I->see('The verification code is incorrect');
$I->submitForm('#contact-form', array(
$I->submitForm('#contact-form', [
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester.email',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
));
]);
$I->dontSee('Name cannot be blank', '.help-inline');
$I->see('Email is not a valid email address.');
$I->dontSee('Subject cannot be blank', '.help-inline');
$I->dontSee('Body cannot be blank', '.help-inline');
$I->dontSee('The verification code is incorrect', '.help-inline');
$I->submitForm('#contact-form', array(
$I->submitForm('#contact-form', [
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester@example.com',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
));
]);
$I->dontSeeElement('#contact-form');
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');

10
apps/basic/tests/functional/LoginCept.php

@ -4,20 +4,20 @@ $I->wantTo('ensure that login works');
$I->amOnPage('?r=site/login');
$I->see('Login', 'h1');
$I->submitForm('#login-form', array());
$I->submitForm('#login-form', []);
$I->dontSee('Logout (admin)');
$I->see('Username cannot be blank');
$I->see('Password cannot be blank');
$I->submitForm('#login-form', array(
$I->submitForm('#login-form', [
'LoginForm[username]' => 'admin',
'LoginForm[password]' => 'wrong',
));
]);
$I->dontSee('Logout (admin)');
$I->see('Incorrect username or password');
$I->submitForm('#login-form', array(
$I->submitForm('#login-form', [
'LoginForm[username]' => 'admin',
'LoginForm[password]' => 'admin',
));
]);
$I->see('Logout (admin)');

1359
apps/basic/tests/functional/TestGuy.php

File diff suppressed because it is too large Load Diff

15
apps/basic/tests/unit/CodeGuy.php

@ -1,23 +1,26 @@
<?php
// This class was automatically generated by build task
// You can change it manually, but it will be overwritten on next build
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile
use Codeception\Maybe;
use \Codeception\Maybe;
use Codeception\Module\CodeHelper;
/**
* Inherited methods
* @method void execute($callable)
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void amTesting($method)
* @method void amTestingMethod($method)
* @method void testMethod($signature)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($role)
* @method void lookForwardTo($achieveValue)
* @method void offsetGet($offset)
* @method void offsetSet($offset, $value)
* @method void offsetExists($offset)
* @method void offsetUnset($offset)
*/
class CodeGuy extends \Codeception\AbstractGuy

57
apps/basic/views/layouts/main.php

@ -3,58 +3,59 @@ use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
/**
* @var $this \yii\base\View
* @var $content string
* @var \yii\web\View $this
* @var string $content
*/
app\config\AppAsset::register($this);
AppAsset::register($this);
?>
<?php $this->beginPage(); ?>
<!DOCTYPE html>
<html lang="en">
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?php echo Yii::$app->charset; ?>"/>
<title><?php echo Html::encode($this->title); ?></title>
<meta charset="<?= Yii::$app->charset ?>"/>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head(); ?>
</head>
<body>
<?php $this->beginBody(); ?>
<?php
NavBar::begin(array(
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => array(
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
),
));
echo Nav::widget(array(
'options' => array('class' => 'navbar-nav pull-right'),
'items' => array(
array('label' => 'Home', 'url' => array('/site/index')),
array('label' => 'About', 'url' => array('/site/about')),
array('label' => 'Contact', 'url' => array('/site/contact')),
],
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
Yii::$app->user->isGuest ?
array('label' => 'Login', 'url' => array('/site/login')) :
array('label' => 'Logout (' . Yii::$app->user->identity->username .')' ,
'url' => array('/site/logout'),
'linkOptions' => array('data-method' => 'post')),
),
));
['label' => 'Login', 'url' => ['/site/login']] :
['label' => 'Logout (' . Yii::$app->user->identity->username . ')' ,
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']],
],
]);
NavBar::end();
?>
<div class="container">
<?php echo Breadcrumbs::widget(array(
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
)); ?>
<?php echo $content; ?>
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= $content ?>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; My Company <?php echo date('Y'); ?></p>
<p class="pull-right"><?php echo Yii::powered(); ?></p>
<p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>

6
apps/basic/views/site/about.php

@ -2,17 +2,17 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>
This is the About page. You may modify the following file to customize its content:
</p>
<code><?php echo __FILE__; ?></code>
<code><?= __FILE__ ?></code>
</div>

22
apps/basic/views/site/contact.php

@ -4,7 +4,7 @@ use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\ContactForm $model
*/
@ -12,7 +12,7 @@ $this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-contact">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
@ -28,17 +28,17 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(array('id' => 'contact-form')); ?>
<?php echo $form->field($model, 'name'); ?>
<?php echo $form->field($model, 'email'); ?>
<?php echo $form->field($model, 'subject'); ?>
<?php echo $form->field($model, 'body')->textArea(array('rows' => 6)); ?>
<?php echo $form->field($model, 'verifyCode')->widget(Captcha::className(), array(
'options' => array('class' => 'form-control'),
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'options' => ['class' => 'form-control'],
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
)); ?>
]) ?>
<div class="form-group">
<?php echo Html::submitButton('Submit', array('class' => 'btn btn-primary')); ?>
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

6
apps/basic/views/site/error.php

@ -3,7 +3,7 @@
use yii\helpers\Html;
/**
* @var yii\base\View $this
* @var yii\web\View $this
* @var string $name
* @var string $message
* @var Exception $exception
@ -13,10 +13,10 @@ $this->title = $name;
?>
<div class="site-error">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?php echo nl2br(Html::encode($message)); ?>
<?= nl2br(Html::encode($message)) ?>
</div>
<p>

2
apps/basic/views/site/index.php

@ -1,6 +1,6 @@
<?php
/**
* @var yii\base\View $this
* @var yii\web\View $this
*/
$this->title = 'My Yii Application';
?>

26
apps/basic/views/site/login.php

@ -3,7 +3,7 @@ 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
*/
@ -11,30 +11,30 @@ $this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<h1><?php echo Html::encode($this->title); ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<?php $form = ActiveForm::begin(array(
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => array('class' => 'form-horizontal'),
'fieldConfig' => array(
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
'labelOptions' => array('class' => 'col-lg-1 control-label'),
),
)); ?>
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]); ?>
<?php echo $form->field($model, 'username'); ?>
<?= $form->field($model, 'username') ?>
<?php echo $form->field($model, 'password')->passwordInput(); ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?php echo $form->field($model, 'rememberMe', array(
<?= $form->field($model, 'rememberMe', [
'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
))->checkbox(); ?>
])->checkbox() ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary']) ?>
</div>
</div>

21
apps/basic/web/css/site.css

@ -18,3 +18,24 @@ body {
font-size: 21px;
padding: 14px 24px;
}
/* add sorting icons to gridview sort links */
a.asc:after, a.desc:after {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
padding-left: 5px;
}
a.asc:after { content: /*"\e113"*/"\e151"; }
a.desc:after { content: /*"\e114"*/"\e152"; }
.sort-numerical a.asc:after { content: "\e153"; }
.sort-numerical a.desc:after { content: "\e154"; }
.sort-ordinal a.asc:after { content: "\e155"; }
.sort-ordinal a.desc:after { content: "\e156"; }

14
apps/basic/web/index-test.php

@ -1,6 +1,6 @@
<?php
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
die('You are not allowed to access this file.');
}
@ -10,9 +10,15 @@ defined('YII_ENV') or define('YII_ENV', 'test');
require_once(__DIR__ . '/../vendor/autoload.php');
require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
Yii::importNamespaces(require(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
$config = require(__DIR__ . '/../config/web-test.php');
$application = new yii\web\Application($config);
$application->run();
if (isset($this)) {
// run in functional tests
$config['class'] = 'yii\web\Application';
return $config;
} else {
// run in acceptance tests
$application = new yii\web\Application($config);
$application->run();
}

1
apps/basic/web/index.php

@ -6,7 +6,6 @@ defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
Yii::importNamespaces(require(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
$config = require(__DIR__ . '/../config/web.php');

1
apps/basic/yii

@ -15,7 +15,6 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/yii/Yii.php');
Yii::importNamespaces(require(__DIR__ . '/vendor/composer/autoload_namespaces.php'));
$config = require(__DIR__ . '/config/console.php');

4
apps/benchmark/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.
POSSIBILITY OF SUCH DAMAGE.

2
apps/benchmark/README.md

@ -27,7 +27,7 @@ DIRECTORY STRUCTURE
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.0.
INSTALLATION

2
apps/benchmark/composer.json

@ -17,7 +17,7 @@
},
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0",
"php": ">=5.4.0",
"yiisoft/yii2": "dev-master"
}
}

12
apps/benchmark/index.php

@ -4,15 +4,15 @@ defined('YII_DEBUG') or define('YII_DEBUG', false);
require(__DIR__ . '/protected/vendor/yiisoft/yii2/yii/Yii.php');
$config = array(
$config = [
'id' => 'benchmark',
'basePath' => __DIR__ . '/protected',
'components' => array(
'urlManager' => array(
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
),
)
);
],
],
];
$application = new yii\web\Application($config);
$application->run();

4
build/build

@ -13,9 +13,9 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/../framework/yii/Yii.php');
$application = new yii\console\Application(array(
$application = new yii\console\Application([
'id' => 'yii-build',
'basePath' => __DIR__,
'controllerNamespace' => 'yii\build\controllers',
));
]);
$application->run();

19
build/controllers/ClassmapController.php

@ -32,7 +32,7 @@ class ClassmapController extends Controller
if ($mapFile === null) {
$mapFile = YII_PATH . '/classes.php';
}
$options = array(
$options = [
'filter' => function ($path) {
if (is_file($path)) {
$file = basename($path);
@ -42,18 +42,15 @@ class ClassmapController extends Controller
}
return null;
},
'only' => array('.php'),
'except' => array(
'only' => ['.php'],
'except' => [
'Yii.php',
'BaseYii.php',
'/debug/',
'/console/',
'/test/',
'/gii/',
),
);
],
];
$files = FileHelper::findFiles($root, $options);
$map = array();
$map = [];
foreach ($files as $file) {
if (($pos = strpos($file, $root)) !== 0) {
die("Something wrong: $file\n");
@ -76,9 +73,9 @@ class ClassmapController extends Controller
* @license http://www.yiiframework.com/license/
*/
return array(
return [
$map
);
];
EOD;
if (is_file($mapFile) && file_get_contents($mapFile) === $output) {

114
build/controllers/LocaleController.php

@ -1,114 +0,0 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\build\controllers;
use yii\console\Exception;
use yii\console\Controller;
/**
* http://www.unicode.org/cldr/charts/supplemental/language_plural_rules.html
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class LocaleController extends Controller
{
public $defaultAction = 'plural';
/**
* Generates the plural rules data.
*
* This command will parse the plural rule XML file from CLDR and convert them
* into appropriate PHP representation to support Yii message translation feature.
* @param string $xmlFile the original plural rule XML file (from CLDR). This file may be found in
* http://www.unicode.org/Public/cldr/latest/core.zip
* Extract the zip file and locate the file "common/supplemental/plurals.xml".
* @throws Exception
*/
public function actionPlural($xmlFile)
{
if (!is_file($xmlFile)) {
throw new Exception("The source plural rule file does not exist: $xmlFile");
}
$xml = simplexml_load_file($xmlFile);
$allRules = array();
$patterns = array(
'/n in 0..1/' => '(n==0||n==1)',
'/\s+is\s+not\s+/i' => '!=', //is not
'/\s+is\s+/i' => '==', //is
'/n\s+mod\s+(\d+)/i' => 'fmod(n,$1)', //mod (CLDR's "mod" is "fmod()", not "%")
'/^(.*?)\s+not\s+in\s+(\d+)\.\.(\d+)/i' => '!in_array($1,range($2,$3))', //not in
'/^(.*?)\s+in\s+(\d+)\.\.(\d+)/i' => 'in_array($1,range($2,$3))', //in
'/^(.*?)\s+not\s+within\s+(\d+)\.\.(\d+)/i' => '($1<$2||$1>$3)', //not within
'/^(.*?)\s+within\s+(\d+)\.\.(\d+)/i' => '($1>=$2&&$1<=$3)', //within
);
foreach ($xml->plurals->pluralRules as $node) {
$attributes = $node->attributes();
$locales = explode(' ', $attributes['locales']);
$rules = array();
if (!empty($node->pluralRule)) {
foreach ($node->pluralRule as $rule) {
$expr_or = preg_split('/\s+or\s+/i', $rule);
foreach ($expr_or as $key_or => $val_or) {
$expr_and = preg_split('/\s+and\s+/i', $val_or);
$expr_and = preg_replace(array_keys($patterns), array_values($patterns), $expr_and);
$expr_or[$key_or] = implode('&&', $expr_and);
}
$expr = preg_replace('/\\bn\\b/', '$n', implode('||', $expr_or));
$rules[] = preg_replace_callback('/range\((\d+),(\d+)\)/', function ($matches) {
if ($matches[2] - $matches[1] <= 5) {
return 'array(' . implode(',', range($matches[1], $matches[2])) . ')';
} else {
return $matches[0];
}
}, $expr);
}
foreach ($locales as $locale) {
$allRules[$locale] = $rules;
}
}
}
// hard fix for "br": the rule is too complex
$allRules['br'] = array(
0 => 'fmod($n,10)==1&&!in_array(fmod($n,100),array(11,71,91))',
1 => 'fmod($n,10)==2&&!in_array(fmod($n,100),array(12,72,92))',
2 => 'in_array(fmod($n,10),array(3,4,9))&&!in_array(fmod($n,100),array_merge(range(10,19),range(70,79),range(90,99)))',
3 => 'fmod($n,1000000)==0&&$n!=0',
);
if (preg_match('/\d+/', $xml->version['number'], $matches)) {
$revision = $matches[0];
} else {
$revision = -1;
}
echo "<?php\n";
echo <<<EOD
/**
* Plural rules.
*
* This file is automatically generated by the "yii locale/plural" command under the "build" folder.
* Do not modify it directly.
*
* The original plural rule data used for generating this file has the following copyright terms:
*
* Copyright © 1991-2007 Unicode, Inc. All rights reserved.
* Distributed under the Terms of Use in http://www.unicode.org/copyright.html.
*
* @revision $revision (of the original plural file)
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
EOD;
echo "\nreturn " . var_export($allRules, true) . ';';
}
}

67
build/controllers/PhpDocController.php

@ -44,7 +44,7 @@ class PhpDocController extends Controller
$root = YII_PATH;
}
$root = FileHelper::normalizePath($root);
$options = array(
$options = [
'filter' => function ($path) {
if (is_file($path)) {
$file = basename($path);
@ -54,16 +54,16 @@ class PhpDocController extends Controller
}
return null;
},
'only' => array('.php'),
'except' => array(
'only' => ['.php'],
'except' => [
'BaseYii.php',
'Yii.php',
'/debug/views/',
'/requirements/',
'/gii/views/',
'/gii/generators/',
),
);
],
];
$files = FileHelper::findFiles($root, $options);
$nFilesTotal = 0;
$nFilesUpdated = 0;
@ -89,7 +89,7 @@ class PhpDocController extends Controller
public function globalOptions()
{
return array_merge(parent::globalOptions(), array('updateFiles'));
return array_merge(parent::globalOptions(), ['updateFiles']);
}
protected function updateClassPropertyDocs($file, $className, $propertyDoc)
@ -115,7 +115,7 @@ class PhpDocController extends Controller
if (trim($lines[1]) == '*' || substr(trim($lines[1]), 0, 3) == '* @') {
$this->stderr("[WARN] Class $className has no short description.\n", Console::FG_YELLOW, Console::BOLD);
}
foreach($lines as $line) {
foreach ($lines as $line) {
if (substr(trim($line), 0, 9) == '* @since ') {
$seenSince = true;
} elseif (substr(trim($line), 0, 10) == '* @author ') {
@ -136,9 +136,9 @@ class PhpDocController extends Controller
$start = $ref->getStartLine() - 2;
$docStart = $start - count(explode("\n", $oldDoc)) + 1;
$newFileContent = array();
$newFileContent = [];
$n = count($fileContent);
for($i = 0; $i < $n; $i++) {
for ($i = 0; $i < $n; $i++) {
if ($i > $start || $i < $docStart) {
$newFileContent[] = $fileContent[$i];
} else {
@ -164,7 +164,7 @@ class PhpDocController extends Controller
{
$lines = explode("\n", $doc);
$n = count($lines);
for($i = 0; $i < $n; $i++) {
for ($i = 0; $i < $n; $i++) {
$lines[$i] = rtrim($lines[$i]);
if (trim($lines[$i]) == '*' && trim($lines[$i + 1]) == '*') {
unset($lines[$i]);
@ -184,7 +184,7 @@ class PhpDocController extends Controller
$lines = explode("\n", $doc);
$propertyPart = false;
$propertyPosition = false;
foreach($lines as $i => $line) {
foreach ($lines as $i => $line) {
if (substr(trim($line), 0, 12) == '* @property ') {
$propertyPart = true;
} elseif ($propertyPart && trim($line) == '*') {
@ -200,7 +200,7 @@ class PhpDocController extends Controller
}
}
$finalDoc = '';
foreach($lines as $i => $line) {
foreach ($lines as $i => $line) {
$finalDoc .= $line . "\n";
if ($i == $propertyPosition) {
$finalDoc .= $properties;
@ -253,16 +253,15 @@ class PhpDocController extends Controller
'[\s\n]{2,}public function [g|s]et(?<name>\w+)\(((?:,? ?\$\w+ ?= ?[^,]+)*|\$\w+(?:, ?\$\w+ ?= ?[^,]+)*)\)#',
$class['content']);
$acrs = array_merge($properties, $gets, $sets);
//print_r($acrs); continue;
$props = array();
$props = [];
foreach ($acrs as &$acr) {
$acr['name'] = lcfirst($acr['name']);
$acr['comment'] = trim(preg_replace('#(^|\n)\s+\*\s?#', '$1 * ', $acr['comment']));
$props[$acr['name']][$acr['kind']] = array(
$props[$acr['name']][$acr['kind']] = [
'type' => $acr['type'],
'comment' => $this->fixSentence($acr['comment']),
);
];
}
ksort($props);
@ -279,11 +278,35 @@ class PhpDocController extends Controller
. ' See [[get'.ucfirst($propName).'()]] and [[set'.ucfirst($propName).'()]] for details.';
}
} elseif (isset($prop['get'])) {
$note = ' This property is read-only.';
// $docline .= '-read';
// check if parent class has setter defined
$c = $className;
$parentSetter = false;
while($parent = get_parent_class($c)) {
if (method_exists($parent, 'set' . ucfirst($propName))) {
$parentSetter = true;
break;
}
$c = $parent;
}
if (!$parentSetter) {
$note = ' This property is read-only.';
// $docline .= '-read';
}
} elseif (isset($prop['set'])) {
$note = ' This property is write-only.';
// $docline .= '-write';
// check if parent class has getter defined
$c = $className;
$parentGetter = false;
while($parent = get_parent_class($c)) {
if (method_exists($parent, 'set' . ucfirst($propName))) {
$parentGetter = true;
break;
}
$c = $parent;
}
if (!$parentGetter) {
$note = ' This property is write-only.';
// $docline .= '-write';
}
} else {
continue;
}
@ -299,12 +322,12 @@ class PhpDocController extends Controller
$phpdoc .= " *\n";
}
}
return array($className, $phpdoc);
return [$className, $phpdoc];
}
protected function match($pattern, $subject)
{
$sets = array();
$sets = [];
preg_match_all($pattern . 'suU', $subject, $sets, PREG_SET_ORDER);
foreach ($sets as &$set)
foreach ($set as $i => $match)

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save