/** * Magic method that redirects static calls to the facade's related service. * * @param string $method * @param array $parameters * @return mixed */ public static function __callStatic($method, $parameters) { $service = static::getServiceName(); if (!static::$serviceContainer) { throw new RuntimeException('Tried to use a facade without setting a service container'); } $instance = static::$serviceContainer->resolve($service); if (!is_object($instance)) { throw new RuntimeException('Facade resolved non-object from the service container'); } if (!method_exists($instance, $method)) { throw new RuntimeException('Call to non-existent method "' . $method . '" on facade instance'); } return static::$serviceContainer->call(array($instance, $method), $parameters); }
/** * Helper method for invoking callables. Silent if the given argument is * not callable. * * Resolves parameters using the service container if available. * * @param mixed $callable * @param array $arguments [optional] * @return mixed */ protected function call($callable, array $arguments = array()) { if (is_callable($callable)) { if ($this->services) { return $this->services->call($callable, $arguments); } else { return call_user_func_array($callable, $arguments); } } return null; }