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