/**
* Creates a new service.
*
* @param string $serviceName
* @param array $args
*
* @return \Exchanger\Contract\ExchangeRateService
*/
public function create($serviceName, array $args = [])
{
if (!$this->registry->has($serviceName)) {
throw new \InvalidArgumentException(sprintf('The service "%s" is not registered.', $serviceName));
}
$classOrCallable = $this->registry->get($serviceName);
if (is_callable($classOrCallable)) {
return call_user_func($classOrCallable);
}
if (is_subclass_of($classOrCallable, Service::class)) {
return new $classOrCallable($this->httpClient, $this->requestFactory, $args);
}
$r = new \ReflectionClass($classOrCallable);
return $r->newInstanceArgs($args);
}