00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00018 abstract class BasePrimitive
00019 {
00020 protected $name = null;
00021 protected $default = null;
00022 protected $value = null;
00023
00024 protected $required = false;
00025 protected $imported = false;
00026
00027 protected $raw = null;
00028
00029 public function __construct($name)
00030 {
00031 $this->name = $name;
00032 }
00033
00034 public function getName()
00035 {
00036 return $this->name;
00037 }
00038
00042 public function setName($name)
00043 {
00044 $this->name = $name;
00045
00046 return $this;
00047 }
00048
00049 public function getDefault()
00050 {
00051 return $this->default;
00052 }
00053
00057 public function setDefault($default)
00058 {
00059 $this->default = $default;
00060
00061 return $this;
00062 }
00063
00064 public function getValue()
00065 {
00066 return $this->value;
00067 }
00068
00069 public function getRawValue()
00070 {
00071 return $this->raw;
00072 }
00073
00074 public function getActualValue()
00075 {
00076 if (null !== $this->value)
00077 return $this->value;
00078 elseif ($this->imported)
00079 return $this->raw;
00080
00081 return $this->default;
00082 }
00083
00084 public function getSafeValue()
00085 {
00086 if ($this->imported)
00087 return $this->value;
00088
00089 return $this->default;
00090 }
00091
00095 public function setValue($value)
00096 {
00097 $this->value = $value;
00098
00099 return $this;
00100 }
00101
00105 public function setRawValue($raw)
00106 {
00107 $this->raw = $raw;
00108
00109 return $this;
00110 }
00111
00112 public function isRequired()
00113 {
00114 return $this->required;
00115 }
00116
00120 public function setRequired($really = false)
00121 {
00122 $this->required = (true === $really ? true : false);
00123
00124 return $this;
00125 }
00126
00130 public function required()
00131 {
00132 $this->required = true;
00133
00134 return $this;
00135 }
00136
00140 public function optional()
00141 {
00142 $this->required = false;
00143
00144 return $this;
00145 }
00146
00147 public function isImported()
00148 {
00149 return $this->imported;
00150 }
00151
00155 public function clean()
00156 {
00157 $this->raw = null;
00158 $this->value = null;
00159 $this->imported = false;
00160
00161 return $this;
00162 }
00163
00164 public function importValue($value)
00165 {
00166 return $this->import(array($this->getName() => $value));
00167 }
00168
00169 protected function import($scope)
00170 {
00171 if (
00172 !empty($scope[$this->name])
00173 || (
00174 isset($scope[$this->name])
00175 && $scope[$this->name] !== ''
00176 )
00177 ) {
00178 $this->raw = $scope[$this->name];
00179
00180 return $this->imported = true;
00181 }
00182
00183 $this->clean();
00184
00185 return null;
00186 }
00187 }
00188 ?>