00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 abstract class BasePropertyType
00017 {
00018 abstract public function getDeclaration();
00019 abstract public function isMeasurable();
00020 abstract public function toColumnType();
00021 abstract public function toPrimitive();
00022
00023 protected $default = null;
00024
00025 public function isGeneric()
00026 {
00027 return true;
00028 }
00029
00030 public function toMethods(
00031 MetaClass $class,
00032 MetaClassProperty $property,
00033 MetaClassProperty $holder = null
00034 )
00035 {
00036 return
00037 $this->toGetter($class, $property, $holder)
00038 .$this->toSetter($class, $property, $holder);
00039 }
00040
00041 public function hasDefault()
00042 {
00043 return ($this->default !== null);
00044 }
00045
00046 public function getDefault()
00047 {
00048 return $this->default;
00049 }
00050
00051 public function setDefault($default)
00052 {
00053 throw new UnsupportedMethodException(
00054 'only generic non-object types can have default values atm'
00055 );
00056 }
00057
00058 public function toGetter(
00059 MetaClass $class,
00060 MetaClassProperty $property,
00061 MetaClassProperty $holder = null
00062 )
00063 {
00064 if ($holder)
00065 $name = $holder->getName().'->get'.ucfirst($property->getName()).'()';
00066 else
00067 $name = $property->getName();
00068
00069 $methodName = 'get'.ucfirst($property->getName());
00070
00071 return <<<EOT
00072
00073 public function {$methodName}()
00074 {
00075 return \$this->{$name};
00076 }
00077
00078 EOT;
00079 }
00080
00081 public function toSetter(
00082 MetaClass $class,
00083 MetaClassProperty $property,
00084 MetaClassProperty $holder = null
00085 )
00086 {
00087 $name = $property->getName();
00088 $methodName = 'set'.ucfirst($name);
00089
00090 if ($holder) {
00091 return <<<EOT
00092
00096 public function {$methodName}(\${$name})
00097 {
00098 \$this->{$holder->getName()}->{$methodName}(\${$name});
00099
00100 return \$this;
00101 }
00102
00103 EOT;
00104 } else {
00105 if ($class->getPattern() instanceof DtoClassPattern)
00106 $classNamePrefix = 'Dto';
00107 else
00108 $classNamePrefix = null;
00109
00110 return <<<EOT
00111
00115 public function {$methodName}(\${$name})
00116 {
00117 \$this->{$name} = \${$name};
00118
00119 return \$this;
00120 }
00121
00122 EOT;
00123 }
00124
00125 Assert::isUnreachable();
00126 }
00127
00128 public function getHint()
00129 {
00130 return null;
00131 }
00132 }
00133 ?>