1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
<?php
namespace hji\membership\models\webservice\abstracts;
abstract class QueryProperties
{
private $propertiesMap = array();
public function __construct()
{
$this->_setPropertiesMap();
}
public function set($property, $value = null)
{
if ($this->hasProperty($property))
{
$lowerCase = strtolower($property);
$property = $this->propertiesMap[$lowerCase];
$this->$property = $value;
}
}
public function get($property)
{
if ($this->hasProperty($property))
{
$lowerCase = strtolower($property);
$property = $this->propertiesMap[$lowerCase];
return $this->$property;
}
}
public function getAll()
{
$properties = array();
foreach ($this->propertiesMap as $property)
{
$properties[$property] = $this->$property;
}
return $properties;
}
public function hasProperty($property)
{
$lowerCase = strtolower($property);
return isset($this->propertiesMap[$lowerCase]);
}
protected function _setPropertiesMap()
{
$class = new \ReflectionClass($this);
$properties = $class->getProperties(\ReflectionProperty::IS_PROTECTED);
$parentProperties = $class->getParentClass()->getProperties(\ReflectionProperty::IS_PROTECTED);
$properties = array_merge($properties, $parentProperties);
$this->propertiesMap = array();
if (!empty($properties))
{
foreach ($properties as $property)
{
$this->propertiesMap[strtolower($property->getName())] = $property->getName();
}
}
}
}