PHP Classes
Icontem

File: DATA/SQLType.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/SQLType.php  
File: DATA/SQLType.php
Role: Class source
Content type: text/plain
Description: SQL type representation.
Class: DATA
Access data stored in MySQL tables like arrays
 

Contents

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

/**
 * SQL type representation.
 * 
 * Right now there will be no support for arbitrary size math
 * operations, but these will be supported by the member
 * functions in the corresponding classes. Outboxing into native
 * php types and doing the math operations outside is discouraged.
 * 
 * All classes will provide __toString() functionality for automatic
 * outboxing into string representation. This will allow character
 * types to be used in the usual string context without having to
 * explicitly outbox the value.
 * 
 */
abstract class DATA_SQLType {
    
/**
     * Flags the type to nullable or not nullable.
     * @var boolean
     */
    
private $nullable;
    
    
/**
     * Flags the value as null.
     * @var boolean
     */
    
private $isnull;
    
    
/**
     * Internal constructor. Sets the type to nullable or not nullable.
     * 
     * @param boolean $nullable True if the type is nullable.
     * @param boolean $isnull True if the initial value is null.
     */
    
protected function __construct($nullable$isnull) {
        
$this->nullable $nullable;
        
$this->isnull false;
        if (
$isnull$this->setNull();
    }
    
    
/**
     * Automatically outboxes the value into a native php string.
     * 
     * @return string String representation of the value.
     */
    
abstract public function __toString();
    
    
/**
     * Indicates if this type is nullable.
     * 
     * @return boolean True if the type is nullable.
     */
    
public function isNullable() {
        return 
$this->nullable;
    }
    
    
/**
     * Indicates if this value is null.
     * 
     * Optionally, can be used statically passing the value by parameter.
     * 
     * @return boolean True if the value is null.
     */
    
public function isNull() {
        if (isset(
$this)) {
            return 
$this->isnull;
        }
        
$value func_get_arg(0);
        if (
$value instanceof DATA_SQLType) {
            return 
$value->isNull();
        } else {
            return 
is_null($value);
        }
    }
    
    
/**
     * Nulls this value.
     * 
     * Throws {@link DATA_NotNullable}.
     */
    
public function setNull() {
        if (!
$this->nullable) {
            
throw new DATA_NotNullable();
        }
        
$this->isnull true;
    }
    
    
/**
     * Internally flag the value as not null.
     */
    
protected function setNotNull() {
        
$this->isnull false;
    }
    
    
/**
     * Outboxes the value into a php native value.
     * 
     * @return mixed Php native value.
     */
    
public function outbox() {
        if (
$this->isnull) return null;
        else return 
$this->__toString();
    }
}
?>

 
  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