You are here

public function DateTimePlus::__call in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::__call()

Implements the magic __call method.

Passes through all unknown calls onto the DateTime object.

Parameters

string $method: The method to call on the decorated object.

array $args: Call arguments.

Return value

mixed The return value from the method on the decorated object. If the proxied method call returns a DateTime object, then return the original DateTimePlus object, which allows function chaining to work properly. Otherwise, the value from the proxied method call is returned.

Throws

\Exception Thrown when the DateTime object is not set.

\BadMethodCallException Thrown when there is no corresponding method on the DateTime object to call.

File

core/lib/Drupal/Component/Datetime/DateTimePlus.php, line 357

Class

DateTimePlus
Wraps DateTime().

Namespace

Drupal\Component\Datetime

Code

public function __call($method, array $args) {

  // @todo consider using assert() as per https://www.drupal.org/node/2451793.
  if (!isset($this->dateTimeObject)) {
    throw new \Exception('DateTime object not set.');
  }
  if (!method_exists($this->dateTimeObject, $method)) {
    throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $method));
  }
  $result = call_user_func_array([
    $this->dateTimeObject,
    $method,
  ], $args);
  return $result === $this->dateTimeObject ? $this : $result;
}