Longman\TelegramBot\Entities\Entity::__call PHP Method

__call() public method

Return the variable for the called getter or magically set properties dynamically.
public __call ( $method, $args ) : mixed | null
$method
$args
return mixed | null
    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;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function __call($method, $args)
 {
     // Only 1 of these can be set, so clear the others when setting a new one.
     if (in_array($method, ['setRequestContact', 'setRequestLocation'], true)) {
         unset($this->request_contact, $this->request_location);
     }
     return parent::__call($method, $args);
 }