20 protected $_published = [];
27 protected function publish($property,$visibility = self::READABLE){
28 if(!is_array($properties = $property)) $properties = [$property => $visibility];
29 elseif(!Record::assoc($properties)) $properties = array_fill_keys($properties,$visibility);
30 $this->_published = array_merge($this->_published,$properties);
38 return property_exists($this,$property) || array_key_exists($property,$this->_published);
46 if($config)
foreach($config as $key => $value)
47 if(property_exists($this,$key)) $this->$key = $value;
48 elseif(method_exists($this,$func_name =
'set' . ucfirst($key))) call_user_func([$this,$func_name],$value);
49 elseif(property_exists($this,$property =
'_' . $key) && !method_exists($this,
'get' . ucfirst($key))) $this->$property = $value;
57 $reflect = new \ReflectionClass($this);
58 $length = strlen($prefix);
60 foreach($reflect->getConstants() as $name => $value)
if(!$prefix || substr($name,0,$length) == $prefix)
61 $constants[substr($name,$length)] = $value;
69 protected function _get($key){
70 throw new \OutOfRangeException(
"Can't get property '$key'");
77 protected function _set($key,$value){
78 throw new \OutOfRangeException(
"Can't set property '$key'");
91 public function get($key){
94 foreach($key as $sub) $result[$sub] = $this->
get($sub);
97 if(property_exists($this,$key))
return $this->$key;
98 if(method_exists($this,$func_name =
'get' . ucfirst($key)))
return call_user_func([$this,$func_name]);
99 if(array_key_exists($key,$this->_published) && ($this->_published[$key] & self::READABLE)){
100 $property =
'_' . $key;
101 return $this->$property;
103 return $this->_get($key);
116 public function set($key,$value = null){
117 if(is_array($key))
foreach($key as $sub => $value) $this->
set($sub,$value);
118 elseif(property_exists($this,$key)) $this->$key = $value;
119 elseif(method_exists($this,$func_name =
'set' . ucfirst($key))) call_user_func([$this,$func_name],$value);
120 elseif(array_key_exists($key,$this->_published) && ($this->_published[$key] & self::WRITEABLE)){
121 $property =
'_' . $key;
122 $this->$property = $value;
124 else $this->_set($key,$value);
128 return $this->
get($key);
132 $this->
set($key,$value);
configure($config)
Configure the object.
_set($key, $value)
Default setter if no specific setter is defined, and the property is also not published (writeable)...
constants($prefix=null)
Return all constants.
publish($property, $visibility=self::READABLE)
Publish a property (or hide it again).
propertyExists($property)
Check if a property exists (public or published).
_get($key)
Default getter if no specific setter is defined, and the property is also not published (readable)...