Swap\Service\Registry::has PHP Method

has() public method

Tells of the registry has the given service.
public has ( string $name ) : boolean
$name string The service name
return boolean
    public function has($name)
    {
        return isset(self::$services[$name]);
    }

Usage Example

Example #1
0
 /**
  * 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);
 }