DtoClassBuilder.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Denis M. Gabaidulin                             *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: DtoClassBuilder.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class DTOClassBuilder extends BaseBuilder
00017     {
00018         public static function build(MetaClass $class)
00019         {
00020             $out = self::getHead();
00021             
00022             if (
00023                 $class->getType()
00024                 &&
00025                     $class->getType()->getId()
00026                     == MetaClassType::CLASS_ABSTRACT
00027             )
00028                 $abstract = "abstract ";
00029             else
00030                 $abstract = null;
00031                 
00032             $out .= $abstract."class AutoDto{$class->getName()}";
00033             
00034             if ($parent = $class->getParent())
00035                 $out .= " extends AutoDto{$parent->getName()}";
00036             
00037             $out .= "\n{\n";
00038             
00039             foreach ($class->getProperties() as $property) {
00040                 if (!self::doPropertyBuild($property))
00041                     continue;
00042                 
00043                 $out .=
00044                     "protected \${$property->getName()} = "
00045                     .
00046                     (
00047                         (
00048                             $property->getRelation()
00049                             &&
00050                                 $property->getRelation()->getId()
00051                                 == MetaRelation::ONE_TO_MANY
00052                         )
00053                             ? "array();\n"
00054                             : "{$property->getType()->getDeclaration()};\n"
00055                     );
00056                 
00057                 if ($property->getFetchStrategyId() == FetchStrategy::LAZY) {
00058                     $out .=
00059                         "protected \${$property->getName()}Id = null;\n";
00060                 }
00061             }
00062             
00063             if (!$abstract) {
00064                 $out .= <<<EOT
00065 
00069     public static function create()
00070     {
00071         return new self;
00072     }
00073     
00074 EOT;
00075             }
00076             
00077             foreach ($class->getProperties() as $property) {
00078                 if (!self::doPropertyBuild($property))
00079                     continue;
00080                 
00081                 $out .= $property->toMethods($class);
00082             }
00083             
00084             $out .= "}\n";
00085             return $out.self::getHeel();
00086         }
00087         
00088         private static function doPropertyBuild(MetaClassProperty $property)
00089         {
00090             // do not redefine parent's properties
00091             if (
00092                 $property->getClass()->getParent()
00093                 && array_key_exists(
00094                     $property->getName(),
00095                     $property->getClass()->getParentsProperties()
00096                 )
00097             )
00098                 return false;
00099             
00100             return true;
00101         }
00102     }
00103 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4