00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 class BooleanType extends BasePropertyType
00017 {
00022 public function setDefault($default)
00023 {
00024 static $boolean = array('true' => true, 'false' => false);
00025
00026 if (!isset($boolean[$default]))
00027 throw new WrongArgumentException(
00028 "strange default value given - '{$default}'"
00029 );
00030
00031 $this->default = $boolean[$default];
00032
00033 return $this;
00034 }
00035
00036 public function getDeclaration()
00037 {
00038 if ($this->hasDefault())
00039 return
00040 $this->default
00041 ? 'true'
00042 : 'false';
00043
00044 return 'null';
00045 }
00046
00047 public function isMeasurable()
00048 {
00049 return false;
00050 }
00051
00052 public function toColumnType()
00053 {
00054 return 'DataType::create(DataType::BOOLEAN)';
00055 }
00056
00057 public function toPrimitive()
00058 {
00059 return 'Primitive::boolean';
00060 }
00061
00062 public function toXsdType()
00063 {
00064 return 'xsd::boolean';
00065 }
00066
00067 public function toGetter(
00068 MetaClass $class,
00069 MetaClassProperty $property,
00070 MetaClassProperty $holder = null
00071 )
00072 {
00073 $name = $property->getName();
00074 $camelName = ucfirst($name);
00075
00076 $methodName = "is{$camelName}";
00077 $compatName = "get{$camelName}";
00078
00079 if ($holder) {
00080 return <<<EOT
00081
00082 public function {$compatName}()
00083 {
00084 return \$this->{$holder->getName()}->{$compatName}();
00085 }
00086
00087 public function {$methodName}()
00088 {
00089 return \$this->{$holder->getName()}->{$methodName}();
00090 }
00091
00092 EOT;
00093 } else {
00094 return <<<EOT
00095
00096 public function {$compatName}()
00097 {
00098 return \$this->{$name};
00099 }
00100
00101 public function {$methodName}()
00102 {
00103 return \$this->{$name};
00104 }
00105
00106 EOT;
00107 }
00108
00109 Assert::isUnreachable();
00110 }
00111
00112 public function toSetter(
00113 MetaClass $class,
00114 MetaClassProperty $property,
00115 MetaClassProperty $holder = null
00116 )
00117 {
00118 $name = $property->getName();
00119 $methodName = 'set'.ucfirst($name);
00120
00121 if ($holder) {
00122 return <<<EOT
00123
00127 public function {$methodName}(\${$name})
00128 {
00129 \$this->{$holder->getName()}->{$methodName}(\${$name});
00130
00131 return \$this;
00132 }
00133
00134 EOT;
00135 } else {
00136 if ($property->isRequired()) {
00137 $method = <<<EOT
00138
00142 public function {$methodName}(\${$name} = false)
00143 {
00144 \$this->{$name} = (\${$name} === true);
00145
00146 return \$this;
00147 }
00148
00149 EOT;
00150 } else {
00151 $method = <<<EOT
00152
00156 public function {$methodName}(\${$name} = null)
00157 {
00158 Assert::isTernaryBase(\${$name});
00159
00160 \$this->{$name} = \${$name};
00161
00162 return \$this;
00163 }
00164
00165 EOT;
00166 }
00167 }
00168
00169 return $method;
00170 }
00171 }
00172 ?>