public function __call($name, $arguments)
{
$m = array($name, substr($name, 0, 3), substr($name, 3));
if (($m[1] == 'get' || $m[1] == 'set') && !empty($m[2])) {
$identifier = lcfirst($m[2]);
if ($m[1] == 'set' && count($arguments) !== 1) {
if (count($arguments) !== 1) {
throw new \InvalidArgumentException(sprintf('One argument is expected for %s method of %s class.', $name, get_class($this)));
}
}
if (in_array($identifier, $this->getServiceNames())) {
//Ensures availability the service interfaces by getters and setters
if ($m[1] == 'get') {
return isset($this->_services[$identifier]) ? $this->_services[$identifier] : null;
} else {
//Set is expected to be here
$this->_services[$identifier] = $arguments[0];
return $this;
}
} else {
if (in_array($identifier, $this->_externalKeys)) {
if ($m[1] == 'get') {
return array_key_exists($identifier, $this->externalIdentifierValues) ? $this->externalIdentifierValues[$identifier] : null;
} else {
//Set is expected to be here.
$this->externalIdentifierValues[$identifier] = $arguments[0];
return $this;
}
} else {
if (in_array($identifier, $this->_properties)) {
if ($m[1] == 'get') {
return array_key_exists($identifier, $this->propertiesData) ? $this->propertiesData[$identifier] : null;
} else {
//Set property is expected to be here.
$this->propertiesData[$identifier] = $arguments[0];
return $this;
}
} else {
if ($this->getReflectionClass()->hasProperty($identifier)) {
$prop = $this->getReflectionClass()->getProperty($identifier);
if ($prop instanceof \ReflectionProperty && $prop->isPublic()) {
if ($m[1] == 'get') {
return $prop->getValue($this);
} else {
//Set property is expected to be here.
$prop->setValue($this, $arguments[0]);
return $this;
}
}
}
}
}
}
}
throw new \BadFunctionCallException(sprintf('Method "%s" does not exist for the class "%s".', $name, get_class($this)));
}