PHP Classes
Icontem

File: DATA/SQLInt.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Alterisio  >  DATA  >  DATA/SQLInt.php  
File: DATA/SQLInt.php
Role: Class source
Content type: text/plain
Description: ANSI SQL Integer data type representation.
Class: DATA
Access data stored in MySQL tables like arrays
 

Contents

Class file image Download
<?php
/**
 * @package DATA
 */

/**
 * ANSI SQL Integer data type representation.
 * 
 * When inboxing, if the field cannot hold the desired value
 * {@link DATA_InvalidInt} is thrown.
 */
class DATA_SQLInt extends DATA_SQLType implements DATA_Number {
    
/**
     * The stored number.
     * @var int
     */
    
protected $number;
    
    
/**
     * Construct a sql integer type with an initial value (optional).
     * 
     * Throws {@link DATA_InvalidInt} when the number to be stored is invalid.
     * 
     * @param boolean $nullable True if the type is nullable.
     * @param null|int|string $number The stored number.
     */
    
public function __construct($nullable$number 0) {
        
$this->setNumber($number);
        
parent::__construct($nullableis_null($number));
    }
    
    
/**
     * Returns the stored number.
     * 
     * @return int The stored number.
     */
    
public function getNumber() {
        return 
$this->number;
    }
    
    
/**
     * Sets the stored number.
     * 
     * Throws {@link DATA_InvalidInt} when the number to be stored is invalid.
     * 
     * @param int|string $number The stored number.
     */
    
public function setNumber($number) {
        if (
is_string($number)) {
            
$toInt = (int)$number;
            if ((string)
$toInt !== $number) {
                
throw new DATA_InvalidInt($number);
            }
        }
        
$this->number = (int)$number;
        
$this->setNotNull();
    }
    
    
public function setNull() {
        
parent::setNull();
        
$this->number null;
    }
    
    
public function __toString() {
        return (string)
$this->number;
    }
    
    
public function outbox() {
        return 
$this->number;
    }
    
    
/**
     * Adds this int to another and returns the result.
     * 
     * Throws {@link DATA_InvalidInt}.
     * 
     * @param DATA_Number $other The number to add.
     * @return DATA_SQLInt The result.
     */
    
public function add(DATA_Number $other) {
        return new 
DATA_SQLInt($this->isNullable(), $this->number $other->getNumber());
    }
    
    
/**
     * Substracts this int to another and returns the result.
     * 
     * Throws {@link DATA_InvalidInt}.
     * 
     * @param DATA_Number $other The number to substract.
     * @return DATA_SQLInt The result.
     */
    
public function substract(DATA_Number $other) {
        return new 
DATA_SQLInt($this->isNullable(), $this->number $other->getNumber());
    }
    
    
/**
     * Multiplies this int to another and returns the result.
     * 
     * Throws {@link DATA_InvalidInt}.
     * 
     * @param DATA_Number $other The number to multiply by.
     * @return DATA_SQLInt The result.
     */
    
public function multiply(DATA_Number $other) {
        return new 
DATA_SQLInt($this->isNullable(), $this->number $other->getNumber());
    }
    
    
/**
     * Divides this int to another and returns the result.
     * 
     * Throws {@link DATA_InvalidInt}.
     * 
     * @param DATA_Number $other The number to divide by.
     * @return DATA_SQLInt The result.
     */
    
public function divide(DATA_Number $other) {
        return new 
DATA_SQLInt($this->isNullable(), (int)($this->number $other->getNumber()));
    }
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products