PHP Classes
elePHPant
Icontem

File: DATA/MySQL5/SQLTimeFactory.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/MySQL5/SQLTimeFactory.php  >  Download  
File: DATA/MySQL5/SQLTimeFactory.php
Role: Class source
Content type: text/plain
Description: A concrete factory for inboxing string with mysql time format into time objects.
Class: DATA
Access data stored in MySQL tables like arrays
Author: By
Last change: + anonymous access
Date: 7 years ago
Size: 1,407 bytes
 

Contents

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

/**
 * A concrete factory for inboxing string with mysql time format into time objects.
 */
class DATA_MySQL5_SQLTimeFactory 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_InvalidTime}.
     *
     * @param mixed $value The value.
     * @return DATA_SQLTime Inboxed value.
     */
   
public function inbox($value) {
        if (
$value instanceof DATA_SQLTime) {
            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]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/', $value)) {
            throw new
DATA_InvalidTime($value);
        }
        list(
$hour, $minutes, $seconds) = explode(':', $value);
        return new
DATA_SQLTime($this->nullable, $hour, $minutes, $seconds);
    }
}
?>