RecordSchema.php 1.15 KB
Newer Older
Carsten Brandt committed
1 2
<?php
/**
3 4 5
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
Carsten Brandt committed
6 7
 */

8
namespace yii\redis;
Carsten Brandt committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

use yii\base\InvalidConfigException;
use yii\db\TableSchema;

/**
 * Class RecordSchema defines the data schema for a redis active record
 *
 * As there is no schema in a redis DB this class is used to define one.
 *
 * @package yii\db\redis
 */
class RecordSchema extends TableSchema
{
	/**
	 * @var string[] column names.
	 */
	public $columns = array();

	/**
	 * @return string the column type
	 */
	public function getColumn($name)
	{
		parent::getColumn($name);
	}

	public function init()
	{
		if (empty($this->name)) {
			throw new InvalidConfigException('name of RecordSchema must not be empty.');
		}
		if (empty($this->primaryKey)) {
			throw new InvalidConfigException('primaryKey of RecordSchema must not be empty.');
		}
		if (!is_array($this->primaryKey)) {
			$this->primaryKey = array($this->primaryKey);
		}
		foreach($this->primaryKey as $pk) {
			if (!isset($this->columns[$pk])) {
				throw new InvalidConfigException('primaryKey '.$pk.' is not a colum of RecordSchema.');
			}
		}
	}
}