/** * @inheritdoc */ public function init() { parent::init(); if (!isset($this->modelClass) && !isset($this->tableName)) { throw new InvalidConfigException('Either "modelClass" or "tableName" must be set.'); } }
public function init() { parent::init(); /** @var ActiveRecord $model */ $model = $this->modelClass; $this->index || ($this->index = $model::index()); $this->type || ($this->type = $model::type()); if (empty($this->type) || empty($this->index)) { throw new InvalidParamException('"index" and "type" must be specified'); } }
/** * 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 an array of data rows (column name => column value), each corresponding to a row in the table. * * If the data file does not exist, an empty array will be returned. * * @return array the data rows to be inserted into the database table. */ protected function getData() { 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(); } }
/** * 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 an array of data rows (column name => column value), each corresponding to a row in the index. * * If the data file does not exist, an empty array will be returned. * * @return array the data rows to be inserted into the database index. */ protected function getData() { if ($this->dataFile === null) { $class = new \ReflectionClass($this); $dataFile = dirname($class->getFileName()) . "/data/{$this->index}/{$this->type}.php"; return is_file($dataFile) ? require $dataFile : []; } else { return parent::getData(); } }
/** * Returns the fixture data. * * This method is called by [[loadData()]] to get the needed fixture data. * * The default implementation will try to return the fixture data by including the external file specified by [[dataFile]]. * The file should return an array of data rows (column name => column value), each corresponding to a row in the collection. * * If the data file does not exist, an empty array will be returned. * * @return array the data rows to be inserted into the collection. */ protected function getData() { if ($this->dataFile === null) { $class = new \ReflectionClass($this); $collectionName = $this->getCollectionName(); $dataFile = dirname($class->getFileName()) . '/data/' . (is_array($collectionName) ? implode('.', $collectionName) : $collectionName) . '.php'; return is_file($dataFile) ? require $dataFile : []; } return parent::getData(); }