PHP Classes

File: DATA/SQLCharFactory.php

Recommend this page to a friend!
  Classes of Martin Alterisio   DATA   DATA/SQLCharFactory.php   Download  
File: DATA/SQLCharFactory.php
Role: Class source
Content type: text/plain
Description: A concrete factory for inboxing strings into char fields.
Class: DATA
Access data stored in MySQL tables like arrays
Author: By
Last change: + anonymous access
Date: 17 years ago
Size: 1,320 bytes
 

Contents

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

/**
 * A concrete factory for inboxing strings into char fields.
 */
class DATA_SQLCharFactory extends DATA_SQLTypeFactory {
   
/**
     * Flags the type to nullable or not nullable.
     * @var boolean
     */
   
protected $nullable;
   
   
/**
     * Constructor.
     *
     * @param boolean $nullable True if the type is nullable.
     * @param int $size Size of char fields constructed by this factory.
     */
   
public function __construct($nullable, $size) {
       
$this->nullable = $nullable;
       
$this->size = $size;
    }
   
   
/**
     * Inboxes a value.
     *
     * Throws {@link DATA_StringTooLarge}.
     *
     * @param mixed $value The value.
     * @return DATA_SQLChar Inboxed value.
     */
   
public function inbox($value) {
        if (
$value instanceof DATA_SQLChar) {
            if (
$this->nullable == $value->isNullable()
             &&
$value->getSize() == $this->size) {
                return clone
$value;
            }
        }
        if (
$value instanceof DATA_SQLType) {
           
$value = $value->outbox();
        }
        if (!
is_null($value)) {
           
$value = (string)$value;
        }
        return new
DATA_SQLChar($this->nullable, $this->size, $value);
    }
}
?>