public function __call($method, $args)
{
//Convert method to snake_case (which is the name of the property)
$property_name = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', substr($method, 3))), '_');
$action = substr($method, 0, 3);
if ($action === 'get') {
$property = $this->getProperty($property_name);
if ($property !== null) {
//Get all sub-Entities of the current Entity
$sub_entities = $this->subEntities();
if (isset($sub_entities[$property_name])) {
return new $sub_entities[$property_name]($property);
}
return $property;
}
} elseif ($action === 'set') {
// Limit setters to specific classes.
if ($this instanceof InlineEntity || $this instanceof Keyboard || $this instanceof KeyboardButton) {
$this->{$property_name} = $args[0];
return $this;
}
}
return null;
}