Swap\Service\Registry::get PHP Method

get() public method

Gets a service.
public get ( string $name ) : string | null
$name string The service name
return string | null
    public function get($name)
    {
        return isset(self::$services[$name]) ? self::$services[$name] : null;
    }

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);
 }