PHP Classes
Icontem

File: VOFormatter.class.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 Christian Velin  >  DbCodeBuilder  >  VOFormatter.class.php  
File: VOFormatter.class.php
Role: Class source
Content type: text/plain
Description: Code generator for VOs
Class: DbCodeBuilder
Generate code to access databases as data objects
 

Contents

Class file image Download
<?php
/**
 * A class to generate value objects from database tables.
 * 
 * @author Christian Velin, christian.velin@conjurer.org
 * @version 0.2
 * @since 0.1 Added phpdoc tags to each generated variable and method.
 * @package DbCodeBuilder
 * 
 * Copyright (C) 2007  Christian Velin
 *
 * This program is free software; distributed under the artistic license.
 */
class VOFormatter
{
    
/**
     * The String variable to store all the generated code.
     *
     * @var String
     */
    
private $output;
    
    
    
public function __construct($tables$columns)
    {
        
$this -> generate($tables$columns);
    }
    
    
    
    
/**
     * Master method to produce workable VO's to work with DAO's.
     *
     * @param Array $tables array of the tables in the db.
     * @param Array $columns recursive array containing all column information.
     */
    
private function generate($tables$columns)
    {
        for (
$i 0$i sizeOf($tables); $i++)
        {
            
$this -> output .= '============ ' ucfirst($tables[$i]) . '.VO.php ============<br><br>';
            
$this -> output .= 'class ' $tables[$i] . 'VO<br>{<br>';
            
$this -> generateVariables($i$columns);
            
$this -> generateSetters($i$columns);
            
$this -> generateGetters($i$columns);
            
$this -> output .= '}<br>';
            
$this -> output .= '============ ' ucfirst($tables[$i]) . '.VO.php ============<br><br>';
        }
    }
    
    
    
    
/**
     * A method to generate code for the needed variables.
     *
     * @param Integer $i keeps track of which table for which we are constructing a VO.
     * @param Array $columns recursive array containing all column information.
     */
    
private function generateVariables($i$columns)
    {
        for (
$j 0$j sizeOf($columns[$i]); $j++)
        {
            
$this -> output .= '/**<br>';
            
$this -> output .= ' * Enter description here...<br>';
            
$this -> output .= ' *<br>';
            
$this -> output .= ' * @var ' .$columns[$i][$j]['Type'] . '<br>';
            
$this -> output .= ' */<br>';

            
$this -> output .= 'private $' .$columns[$i][$j]['Field'] .';<br><br>';
        }
        
$this -> output .= '<br><br>';
    }
    
    
    
    
/**
     * Method to generate the 'setter' methods.
     *
     * @param Integer $i keeps track of which table for which we are constructing a VO.
     * @param Array $columns recursive array containing all column information.
     */
    
private function generateSetters($i$columns)
    {
        for (
$j 0$j sizeOf($columns[$i]); $j++)
        {
            
$this -> output .= '/**<br>';
            
$this -> output .= ' * Enter description here...<br>';
            
$this -> output .= ' *<br>';
            
$this -> output .= ' * @param ' .$columns[$i][$j]['Type'] . ' $' .$columns[$i][$j]['Field'] . '<br>';
            
$this -> output .= ' */<br>';
            
$this -> output .= 'public function set' ucfirst($columns[$i][$j]['Field']) . '($' $columns[$i][$j]['Field'] . ')<br>';
            
$this -> output .= '{<br>';
            
$this -> output .= '$this -> ' $columns[$i][$j]['Field'] . ' = $' $columns[$i][$j]['Field'] . ';<br>';
            
$this -> output .= '}<br><br><br><br>';
        }
    }
    
    
    
    
/**
     * Method to generate the 'getter' methods.
     *
     * @param Integer $i keeps track of which table for which we are constructing a VO.
     * @param Array $columns recursive array containing all column information.
     */
    
private function generateGetters($i$columns)
    {
        for (
$j 0$j sizeOf($columns[$i]); $j++)
        {
            
$this -> output .= '/**<br>';
             
$this -> output .= '* Enter description here...<br>';
            
$this -> output .= ' *<br>';
            
$this -> output .= ' * @return ' .$columns[$i][$j]['Type'] . '<br>';
            
$this -> output .= ' */<br>';
            
$this -> output .= 'public function get' ucfirst($columns[$i][$j]['Field']) . '()<br>';
            
$this -> output .= '{<br>';
            
$this -> output .= 'return $this -> ' $columns[$i][$j]['Field'] . ';<br>';
            
$this -> output .= '}<br><br><br><br>';
        }
    }
    
    
    
    
/**
     * Method to get the generated code.
     *
     * @return String the generated VO(s).
     */
        
public function getOutput()
    {
        return 
$this -> output;
    }
}
?>

 
  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