<?php
 
/**
 
 * @package DATA
 
 */
 
 
/**
 
 * A concrete factory for inboxing php values into decimal fields.
 
 */
 
class DATA_SQLDecimalFactory extends DATA_SQLTypeFactory {
 
    /**
 
     * Flags the type to nullable or not nullable.
 
     * @var boolean
 
     */
 
    protected $nullable;
 
    /**
 
     * How many digits can hold this field.
 
     * @var int
 
     */
 
    protected $precision;
 
    /**
 
     * How many digits after the decimal point this field has.
 
     * @var int
 
     */
 
    protected $scale;
 
    
 
    /**
 
     * Constructor.
 
     * 
 
     * @param boolean $nullable True if the type is nullable.
 
     */
 
    public function __construct($nullable, $precision, $scale) {
 
        $this->nullable = $nullable;
 
        $this->precision = $precision;
 
        $this->scale = $scale;
 
    }
 
    
 
    /**
 
     * Inboxes a value.
 
     * 
 
     * Throws {@link DATA_InvalidDecimal}.
 
     * 
 
     * @param mixed $value The value.
 
     * @return DATA_SQLDecimal Inboxed value.
 
     */
 
    public function inbox($value) {
 
        if ($value instanceof DATA_SQLDecimal) {
 
            if ($this->nullable == $value->isNullable()
 
             && $value->getPrecision() == $this->precision
 
             && $value->getScale() == $this->scale) {
 
                return clone $value;
 
            }
 
        }
 
        if ($value instanceof DATA_SQLType) {
 
            $value = $value->outbox();
 
        }
 
        return new DATA_SQLDecimal($this->nullable, $this->precision, $this->scale, $value);
 
    }
 
}
 
?>
 
 
 |