PHP Classes
Icontem

File: DATA/MySQL5/SQLDatetimeFactory.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/MySQL5/SQLDatetimeFactory.php  
File: DATA/MySQL5/SQLDatetimeFactory.php
Role: Class source
Content type: text/plain
Description: A concrete factory for inboxing string with mysql datetime format into datetime objects.
Class: DATA
Access data stored in MySQL tables like arrays
 

Contents

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

/**
 * A concrete factory for inboxing string with mysql datetime format
 * into datetime objects.
 */
class DATA_MySQL5_SQLDatetimeFactory extends DATA_SQLTypeFactory {
    
/**
     * Flags the type to nullable or not nullable.
     * @var boolean
     */
    
private $nullable;
    
    
/**
     * Constructor.
     * 
     * @param boolean $nullable True if the type is nullable.
     */
    
public function __construct($nullable) {
        
$this->nullable $nullable;
    }
    
    
/**
     * Inboxes a value.
     * 
     * Throws {@link DATA_InvalidDatetime}.
     * 
     * @param mixed $value The value.
     * @return DATA_SQLDatetime Inboxed value.
     */
    
public function inbox($value) {
        if (
$value instanceof DATA_SQLDatetime) {
            if (
$this->nullable == $value->isNullable()) {
                return 
clone $value;
            }
        }
        if (
$value instanceof DATA_SQLType) {
            
$value $value->outbox();
        }
        if (
$value === null) {
            return new 
DATA_SQLDate($this->nullable);
        }
        if (!
preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/'$value)) {
            
throw new DATA_InvalidDatetime($value);
        }
        list(
$date$time) = explode(' '$value);
        list(
$year$month$day) = explode('-'$date);
        list(
$hour$minutes$seconds) = explode(':'$time);
        return new 
DATA_SQLDatetime($this->nullable$year$month$day$hour$minutes$seconds);
    }
}
?>

 
  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