Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class AutoProtoClassBuilder extends BaseBuilder
00016 {
00017 public static function build(MetaClass $class)
00018 {
00019 $out = self::getHead();
00020
00021 $parent = $class->getParent();
00022
00023 if ($class->hasBuildableParent())
00024 $parentName = 'Proto'.$parent->getName();
00025 else
00026 $parentName = 'AbstractProtoClass';
00027
00028 $out .= <<<EOT
00029 abstract class AutoProto{$class->getName()} extends {$parentName}
00030 {
00031 EOT;
00032 $classDump = self::dumpMetaClass($class);
00033
00034 $out .= <<<EOT
00035
00036 {$classDump}
00037 }
00038
00039 EOT;
00040
00041 return $out.self::getHeel();
00042 }
00043
00044 private static function dumpMetaClass(MetaClass $class)
00045 {
00046 $propertyList = $class->getWithInternalProperties();
00047
00048 $out = <<<EOT
00049 protected function makePropertyList()
00050 {
00051
00052 EOT;
00053
00054 if ($class->hasBuildableParent()) {
00055 $out .= <<<EOT
00056 return
00057 array_merge(
00058 parent::makePropertyList(),
00059 array(
00060
00061 EOT;
00062 if ($class->getIdentifier()) {
00063 $propertyList[$class->getIdentifier()->getName()] =
00064 $class->getIdentifier();
00065 }
00066 } else {
00067 $out .= <<<EOT
00068 return array(
00069
00070 EOT;
00071 }
00072
00073 $list = array();
00074
00075 foreach ($propertyList as $property) {
00076 $list[] =
00077 "'{$property->getName()}' => "
00078 .$property->toLightProperty($class)->toString();
00079 }
00080
00081 $out .= implode(",\n", $list);
00082
00083 if ($class->hasBuildableParent()) {
00084 $out .= "\n)";
00085 }
00086
00087 $out .= <<<EOT
00088
00089 );
00090 }
00091 EOT;
00092 return $out;
00093 }
00094 }
00095 ?>