Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class BusinessClassBuilder extends OnceBuilder
00016 {
00017 public static function build(MetaClass $class)
00018 {
00019 $out = self::getHead();
00020
00021 if ($type = $class->getType())
00022 $typeName = $type->toString().' ';
00023 else
00024 $typeName = null;
00025
00026 $interfaces = ' implements Prototyped';
00027
00028 if (
00029 $class->getPattern()->daoExists()
00030 && (!$class->getPattern() instanceof AbstractClassPattern)
00031 ) {
00032 $interfaces .= ', DAOConnected';
00033
00034 $daoName = $class->getName().'DAO';
00035 $dao = <<<EOT
00039 public static function dao()
00040 {
00041 return Singleton::getInstance('{$daoName}');
00042 }
00043
00044 EOT;
00045 } else
00046 $dao = null;
00047
00048 $out .= <<<EOT
00049 {$typeName}class {$class->getName()} extends Auto{$class->getName()}{$interfaces}
00050 {
00051 EOT;
00052
00053 if (!$type || $type->getId() !== MetaClassType::CLASS_ABSTRACT) {
00054 $customCreate = null;
00055
00056 if (
00057 $class->getFinalParent()->getPattern()
00058 instanceof InternalClassPattern
00059 ) {
00060 $parent = $class;
00061
00062 while ($parent = $parent->getParent()) {
00063 $info = new ReflectionClass($parent->getName());
00064
00065 if (
00066 $info->hasMethod('create')
00067 && ($info->getMethod('create')->getParameters() > 0)
00068 ) {
00069 $customCreate = true;
00070 break;
00071 }
00072 }
00073 }
00074
00075 if ($customCreate) {
00076 $creator = $info->getMethod('create');
00077
00078 $declaration = array();
00079
00080 foreach ($creator->getParameters() as $parameter) {
00081 $declaration[] =
00082 '$'.$parameter->getName()
00083
00084 .' = '
00085 .(
00086 $parameter->getDefaultValue()
00087 ? $parameter->getDefaultValue()
00088 : 'null'
00089 );
00090 }
00091
00092 $declaration = implode(', ', $declaration);
00093
00094 $out .= <<<EOT
00095
00099 public static function create({$declaration})
00100 {
00101 return new self({$declaration});
00102 }
00103
00104 EOT;
00105 } else {
00106 $out .= <<<EOT
00107
00111 public static function create()
00112 {
00113 return new self;
00114 }
00115
00116 EOT;
00117 }
00118
00119 $protoName = 'Proto'.$class->getName();
00120
00121 $out .= <<<EOT
00122
00123 {$dao}
00127 public static function proto()
00128 {
00129 return Singleton::getInstance('{$protoName}');
00130 }
00131
00132 EOT;
00133
00134 }
00135
00136 $out .= <<<EOT
00137
00138
00139 }
00140
00141 EOT;
00142 return $out.self::getHeel();
00143 }
00144 }
00145 ?>