Commit d28812e7 by kate-kate

Merge branch 'master' into mongo-fixture

parents d5d810dd b85142a4
......@@ -3,12 +3,9 @@
namespace tests\unit\models;
use yii\codeception\TestCase;
use yii\test\DbTestTrait;
class UserTest extends TestCase
{
use DbTestTrait;
protected function setUp()
{
parent::setUp();
......
......@@ -57,10 +57,10 @@ class SiteController extends Controller
return [
'access' => [
'class' => \yii\web\AccessControl::className(),
'only' => ['special'],
'only' => ['special-callback'],
'rules' => [
[
'actions' => ['special'],
'actions' => ['special-callback'],
'allow' => true,
'matchCallback' => function ($rule, $action) {
return date('d-m') === '31-10';
......@@ -68,6 +68,17 @@ class SiteController extends Controller
],
```
And the action:
```php
// ...
// Match callback called! This page can be accessed only each October 31st
public function actionSpecialCallback()
{
return $this->render('happy-halloween');
}
```
Sometimes you want a custom action to be taken when access is denied. In this case you can specify `denyCallback`.
Role based access control (RBAC)
......
Creating issues
Report an Issue
===============
You got into rough corner while working with yii, or you found a bug? We are very sorry for that, but we can sort that
out together.
Please follow the guidelines below when creating an issue so that your issue can be more promptly resolved:
- If you are unsure about a function, you may ask on IRC or the forums. If the documentation is unclear, open a separate
issue.
- Please use English if possible.
- Make sure it is clear what is the problem and how to reproduce it.
* Provide information including: the version of PHP and Yii, the type of operating system and Web server, browser type and version;
* Provide the **complete** error call stack if available. A screenshot to explain the issue is very welcome.
* Describe the steps for reproducing the issue. It would be even better if you could provide code to reproduce the issue.
If you are going to report security issue please **do not** use the issue tracker and instead
[contact us directly](http://www.yiiframework.com/security/).
**Do not report an issue if**
* you are asking how to use some Yii feature. You should use [the forum](http://www.yiiframework.com/forum/index.php/forum/42-general-discussions-for-yii-20/) or [chat room](http://www.yiiframework.com/chat/) for this purpose.
* your issue is about security. Please [contact us directly](http://www.yiiframework.com/security/) to report security issues.
**Avoid duplicated issues**
Before you report an issue, please search through [existing issues](https://github.com/yiisoft/yii2/issues) to see if your issue is already reported or fixed to make sure you are not reporting a duplicated issue. Also make sure you have the latest version of Yii and see if the issue still exists.
......@@ -174,7 +174,6 @@ return [
'yii\rbac\Manager' => YII_PATH . '/rbac/Manager.php',
'yii\rbac\PhpManager' => YII_PATH . '/rbac/PhpManager.php',
'yii\requirements\YiiRequirementChecker' => YII_PATH . '/requirements/YiiRequirementChecker.php',
'yii\test\DbTestTrait' => YII_PATH . '/test/DbTestTrait.php',
'yii\validators\BooleanValidator' => YII_PATH . '/validators/BooleanValidator.php',
'yii\validators\CompareValidator' => YII_PATH . '/validators/CompareValidator.php',
'yii\validators\DateValidator' => YII_PATH . '/validators/DateValidator.php',
......
......@@ -100,16 +100,13 @@ class ActiveFixture extends BaseActiveFixture
*/
protected function getData()
{
if ($this->dataFile === false) {
return [];
}
if ($this->dataFile !== null) {
$dataFile = Yii::getAlias($this->dataFile);
} else {
if ($this->dataFile === null) {
$class = new \ReflectionClass($this);
$dataFile = dirname($class->getFileName()) . '/data/' . $this->getTableSchema()->fullName . '.php';
}
return is_file($dataFile) ? require($dataFile) : [];
} else {
return parent::getData();
}
}
/**
......
......@@ -31,6 +31,11 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
*/
public $data = [];
/**
* @var string|boolean the file path or path alias of the data file that contains the fixture data
* to be returned by [[getData()]]. You can set this property to be false to prevent loading any data.
*/
public $dataFile;
/**
* @var \yii\db\ActiveRecord[] the loaded AR models
*/
private $_models = [];
......@@ -66,4 +71,37 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
}
return $this->_models[$name] = $modelClass::find($keys);
}
/**
* Loads the fixture.
*
* The default implementation simply stores the data returned by [[getData()]] in [[data]].
* You should usually override this method by putting the data into the underlying database.
*/
public function load()
{
$this->data = $this->getData();
}
/**
* Returns the fixture data.
*
* The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
* The file should return the data array that will be stored in [[data]] after inserting into the database.
*
* @return array the data to be put into the database
* @throws InvalidConfigException if the specified data file does not exist.
*/
protected function getData()
{
if ($this->dataFile === false || $this->dataFile === null) {
return [];
}
$dataFile = Yii::getAlias($this->dataFile);
if (is_file($dataFile)) {
return require($dataFile);
} else {
throw new InvalidConfigException("Fixture data file does not exist: {$this->dataFile}");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment