PHP Classes
elePHPant
Icontem

File: DATA/SQLDecimalFactory.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Alterisio  >  DATA  >  DATA/SQLDecimalFactory.php  >  Download  
File: DATA/SQLDecimalFactory.php
Role: Class source
Content type: text/plain
Description: A concrete factory for inboxing php values into decimal fields.
Class: DATA
Access data stored in MySQL tables like arrays
Author: By
Last change: + anonymous access
Date: 7 years ago
Size: 1,547 bytes
 

Contents

Class file image Download
<?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);
    }
}
?>