<?php
/**
* @package DATA
*/
/**
* A concrete factory for inboxing strings into char fields.
*/
class DATA_SQLCharFactory extends DATA_SQLTypeFactory {
/**
* Flags the type to nullable or not nullable.
* @var boolean
*/
protected $nullable;
/**
* Constructor.
*
* @param boolean $nullable True if the type is nullable.
* @param int $size Size of char fields constructed by this factory.
*/
public function __construct($nullable, $size) {
$this->nullable = $nullable;
$this->size = $size;
}
/**
* Inboxes a value.
*
* Throws {@link DATA_StringTooLarge}.
*
* @param mixed $value The value.
* @return DATA_SQLChar Inboxed value.
*/
public function inbox($value) {
if ($value instanceof DATA_SQLChar) {
if ($this->nullable == $value->isNullable()
&& $value->getSize() == $this->size) {
return clone $value;
}
}
if ($value instanceof DATA_SQLType) {
$value = $value->outbox();
}
if (!is_null($value)) {
$value = (string)$value;
}
return new DATA_SQLChar($this->nullable, $this->size, $value);
}
}
?>
|