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