<?php
namespace Phinx\Db\Table;
class Column
{
protected $name;
protected $type;
protected $limit = null;
protected $null = false;
protected $default = null;
protected $identity = false;
protected $precision;
protected $scale;
protected $after;
protected $update;
protected $comment;
protected $signed = true;
protected $timezone = false;
protected $properties = array();
protected $values;
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setType($type)
{
$this->type = $type;
return $this;
}
public function getType()
{
return $this->type;
}
public function setLimit($limit)
{
$this->limit = $limit;
return $this;
}
public function getLimit()
{
return $this->limit;
}
public function setNull($null)
{
$this->null = (bool) $null;
return $this;
}
public function getNull()
{
return $this->null;
}
public function isNull()
{
return $this->getNull();
}
public function setDefault($default)
{
$this->default = $default;
return $this;
}
public function getDefault()
{
return $this->default;
}
public function setIdentity($identity)
{
$this->identity = $identity;
return $this;
}
public function getIdentity()
{
return $this->identity;
}
public function isIdentity()
{
return $this->getIdentity();
}
public function setAfter($after)
{
$this->after = $after;
return $this;
}
public function getAfter()
{
return $this->after;
}
public function setUpdate($update)
{
$this->update = $update;
return $this;
}
public function getUpdate()
{
return $this->update;
}
public function setPrecision($precision)
{
$this->precision = $precision;
return $this;
}
public function getPrecision()
{
return $this->precision;
}
public function setScale($scale)
{
$this->scale = $scale;
return $this;
}
public function getScale()
{
return $this->scale;
}
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
public function getComment()
{
return $this->comment;
}
public function setSigned($signed)
{
$this->signed = (bool) $signed;
return $this;
}
public function getSigned()
{
return $this->signed;
}
public function isSigned()
{
return $this->getSigned();
}
public function setTimezone($timezone)
{
$this->timezone = (bool) $timezone;
return $this;
}
public function getTimezone()
{
return $this->timezone;
}
public function isTimezone()
{
return $this->getTimezone();
}
public function setProperties($properties)
{
$this->properties = $properties;
return $this;
}
public function getProperties()
{
return $this->properties;
}
public function setValues($values)
{
if (!is_array($values)) {
$values = preg_split('/,\s*/', $values);
}
$this->values = $values;
return $this;
}
public function getValues()
{
return $this->values;
}
protected function getValidOptions()
{
return array(
'limit',
'default',
'null',
'identity',
'precision',
'scale',
'after',
'update',
'comment',
'signed',
'timezone',
'properties',
'values',
);
}
protected function getAliasedOptions()
{
return array(
'length' => 'limit',
);
}
public function setOptions($options)
{
$validOptions = $this->getValidOptions();
$aliasOptions = $this->getAliasedOptions();
foreach ($options as $option => $value) {
if (isset($aliasOptions[$option])) {
$option = $aliasOptions[$option];
}
if (!in_array($option, $validOptions, true)) {
throw new \RuntimeException(sprintf('"%s" is not a valid column option.', $option));
}
$method = 'set' . ucfirst($option);
$this->$method($value);
}
return $this;
}
}