|
- <?php
-
-
- namespace yii\test;
-
- use Yii;
- use yii\base\ArrayAccessTrait;
- use yii\base\InvalidConfigException;
-
-
- class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, \Countable
- {
- use ArrayAccessTrait;
-
-
-
- public $data = [];
-
-
- public $dataFile;
-
-
-
-
- public function load()
- {
- $this->data = $this->getData();
- }
-
-
-
- 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}");
- }
- }
-
-
-
- public function unload()
- {
- parent::unload();
- $this->data = [];
- }
- }
|