00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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 ?>