ContainerClassBuilder.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2006-2007 by Konstantin V. Arkhipov                     *
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: ContainerClassBuilder.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class ContainerClassBuilder extends OnceBuilder
00017     {
00018         public static function build(MetaClass $class)
00019         {
00020             throw new UnsupportedMethodException();
00021         }
00022         
00023         public static function buildContainer(
00024             MetaClass $class, MetaClassProperty $holder
00025         )
00026         {
00027             $out = self::getHead();
00028             
00029             $containerName = $class->getName().ucfirst($holder->getName()).'DAO';
00030             
00031             $out .=
00032                 'final class '
00033                 .$containerName
00034                 .' extends '
00035                 .$holder->getRelation()->toString().'Linked'
00036                 ."\n{\n";
00037 
00038             $className = $class->getName();
00039             $propertyName = strtolower($className[0]).substr($className, 1);
00040             
00041             $remoteColumnName = $holder->getType()->getClass()->getTableName();
00042             
00043             $out .= <<<EOT
00044 public function __construct({$className} \${$propertyName}, \$lazy = false)
00045 {
00046     parent::__construct(
00047         \${$propertyName},
00048         {$holder->getType()->getClassName()}::dao(),
00049         \$lazy
00050     );
00051 }
00052 
00056 public static function create({$className} \${$propertyName}, \$lazy = false)
00057 {
00058     return new self(\${$propertyName}, \$lazy);
00059 }
00060 
00061 EOT;
00062 
00063             if ($holder->getRelation()->getId() == MetaRelation::MANY_TO_MANY) {
00064                 $out .= <<<EOT
00065 
00066 public function getHelperTable()
00067 {
00068     return '{$class->getTableName()}_{$remoteColumnName}';
00069 }
00070 
00071 public function getChildIdField()
00072 {
00073     return '{$remoteColumnName}_id';
00074 }
00075 
00076 EOT;
00077             }
00078             
00079             $out .= <<<EOT
00080 
00081 public function getParentIdField()
00082 {
00083     return '{$class->getTableName()}_id';
00084 }
00085 
00086 EOT;
00087             
00088             
00089             $out .= "}\n";
00090             $out .= self::getHeel();
00091             
00092             return $out;
00093         }
00094     }
00095 ?>

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