/** * Helper method to find and execute a command. Magic method calls must be * enabled on the client to use this functionality. * * @param string $method Name of the command object to instantiate * @param array $args Arguments to pass to the command * * @return mixed * @throws BadMethodCallException when a command is not found or magic * methods are disabled */ public function __call($method, $args = null) { if ($this->magicMethodBehavior == self::MAGIC_CALL_DISABLED) { throw new BadMethodCallException("Missing method {$method}. Enable magic calls to use magic methods with command names."); } $command = $this->getCommand(Inflector::snake($method), $args); return $this->magicMethodBehavior == self::MAGIC_CALL_RETURN ? $command : $this->execute($command); }
/** * Enables magic methods for setting parameters. * * @param string $method Name of the parameter to set * @param array $args (optional) Arguments to pass to the command * * @return AbstractCommand * @throws BadMethodCallException when a parameter doesn't exist */ public function __call($method, $args = null) { // Ensure magic method call behavior is enabled if (!$this->get('command.magic_method_call')) { throw new BadMethodCallException('Magic method calls are disabled ' . 'for this command. Consider enabling magic method calls by ' . 'setting the command.magic_method_call parameter to true.'); } if ($args && strpos($method, 'set') === 0) { // Convert the method into the snake cased parameter key $key = Inflector::snake(substr($method, 3)); // If the parameter exists, set it if (array_key_exists($key, $this->apiCommand->getParams())) { $this->set($key, $args[0]); return $this; } } // If the method is not a set method, or the parameter doesn't exist, fail throw new BadMethodCallException("Missing method {$method}."); }