Get the client

@param string  $name
@param Closure $closure

@return mixed
@throws ServiceNotFound
516736
public function client($name, Closure $closure = null)
    {
        if ($this->has($name)) {
            /** @var Service $service */
            $service = $this->services[$name];

            if (is_null($service->getClient())) {
                $client = new Client($service->getWsdl(), $service->getOptions(), $service->getHeaders());
              
                $service->client($client);
            } else {
                $client = $service->getClient();
            }

            return $closure($client);
        }

        throw new ServiceNotFound("Service '" . $name . "' not found.");
    }
741782
public function resolveClosure(\Closure $closure)
    {
        $reflection = new \ReflectionFunction($closure);

        $dependencies = $reflection->getParameters();
        $instances = $this->resolveDependencies($dependencies); // Actually resolve the dependencies
        $o = $reflection->invokeArgs($instances);

        return $o;
    }
818778
public function of($name, Closure $callback = null): Handler
    {
        if ($name instanceof Closure) {
            $callback = $name;
            $name = $this->getDefaultDriver();
        }

        $instance = $this->make($name);

        if ($instance instanceof Handler && ! \is_null($callback)) {
            $callback($instance);
        }

        return $instance;
    }
402693
public function add($name, \Closure $closure)
    {
        $test = new Test($name, $closure);
        $this->addTest($test);

        return $test;
    }
305933
public function filter(\Closure $closure)
    {
        $newInstance = new self();
        $newInstance->setArray(array_filter($this->array, $closure));
        return $newInstance;
    }
541714
public function get($name, array $parameters = [])
    {
        // Shared services are preserved through whole request
        if (isset($this->shared[$name])) {
            return $this->shared[$name];
        }

        if (!$this->has($name)) {
            throw new NotFoundException('No definition found for service "' . $name . '".');
        }

        $definition = $this->definitions[$name];

        // Alias is a link to another definition
        if (isset($definition['alias'])) {
            return $this->get($definition['alias']);
        }

        // "Init" directive is a function that returns instance of service
        if (isset($definition['init'])) {
            $service_class = call_user_func($definition['init'], $this, $parameters);

            if ($service_class === false) {
                throw new NotFoundException('"Init" directive for service "' . $name . '" did not produced any object.');
            }
        } else {
            $arguments = [];

            // Array of arguments which are given to constructor method
            if (isset($definition['arguments'])) {
                $arguments = $this->resolveArrayOfArguments($definition['arguments'], $parameters);
            }

            // Service is made by static method
            if (isset($definition['static'])) {
                $service_class = call_user_func_array([$definition['class'], $definition['static']], $arguments);

                if ($service_class === false) {
                    throw new NotFoundException('Class "' . $definition['class'] . '" for service "' . $name . '" was not found.');
                }
            } else {
                // Service is made by normal constructor
                try {
                    $reflection_class = new \ReflectionClass($definition['class']);
                } catch (\ReflectionException $e) {
                    throw new NotFoundException('Class "' . $definition['class'] . '" for service "' . $name . '" was not found.');
                }

                $service_class = $reflection_class->newInstanceArgs($arguments);
            }
        }

        // "After" directive is a function that is called after instantiation of service object
        if (isset($definition['after'])) {
            call_user_func($definition['after'], $this, $service_class, $parameters);
        }

        // Preserve shared service
        if (isset($definition['shared']) && $definition['shared'] === true) {
            $this->shared[$name] = $service_class;
        }

        return $service_class;
    }
55673
public function getClient($name = null)
    {
        if (null === $name) {
            $name = $this->defaultClientName;
        }

        if (in_array($name, $this->getClientNames())) {
            return $this->clients[$name];
        }

        throw new \InvalidArgumentException(($name === null ? 'default client' : 'client ' . $name) . ' not configured');
    }
1354602
public static function getOrSet($key, \Closure $closure)
    {
        $key = Cache::key($key);
        if (!isset(self::$cache[$key])) {
            self::$cache[$key] = $closure();
        }
        return self::$cache[$key];
    }
248693
public function call(Closure $callback = null, $caller = null)
    {
        if ($callback instanceof Closure) {
            // Make dependency injection possible
            $parameters = $this->resolveMethodDependencies(
                [$caller], new ReflectionFunction($callback)
            );
            call_user_func_array($callback, $parameters);
        }

        return $caller;
    }
188229
public function add($name, Closure $closure)
  {
    if (!$this->has($name)) {
      $service = new Service();

      $closure($service);

      $this->services[$name] = $service;

      return $this;
    }

    throw new ServiceAlreadyExists("Service '" . $name . "' already exists.");
  }
363294
protected function _service($name, $definition, $params)
    {
        if ($definition instanceof Closure) {
            $type = 'singleton';
            $definition = call_user_func_array($definition, $params);
            $this->_definitions[$name] = compact('definition', 'type');
        }
        return $definition;
    }
288136
public static function get($name, $closure = false)
    {

        if (!is_string($name)) {
            throw new \Exception('Cache key must be a string.');
        }

        // First check php-memory cache
        if (isset(self::$cache[$name])) {
            // Cache hit!
            self::$cacheHit = true;
            return self::$cache[$name];
        }

        if (self::$config['memcached']['enabled']) {
            // Connect if not connected
            self::memcachedConnect();

            // Check if in memcached
            $val = self::$memcached->get($name);

            if (self::$memcached->getResultCode() == \Memcached::RES_SUCCESS) {
                // Cache hit!
                self::$cacheHit = true;

                // Set php-memory cache
                self::$cache[$name] = $val;
                return $val;
            }
        }

        self::$cacheHit = false;

        // If no other way to get value, return
        if (!is_callable($closure)) {
            return null;
        }

        // Call given closure to get value
        $val = $closure();

        // Nothing returned, no need to store it
        if (is_null($val)) {
            return null;
        }

        // Store closure-returned value in cache
        self::set($name, $val);

        return $val;
    }
856711
protected function getCachedProperty($name, \Closure $factory)
    {
        $name = (string) $name;
        if (!array_key_exists($name, $this->gettersCache)) {
            $this->gettersCache[$name] = call_user_func($factory);
        }

        return $this->gettersCache[$name];
    }
859501
public function get($name,$default=null)
    {

        // Return null if the service is not in the container
        if(!isset($this->instances[$name]))
             return $default;

        if(array_key_exists($name,$this->bind))
            return $this->resolve($name);


        // Check if the service has been resolved in the container
        if(!$this->resolved[$name]){

            $this->instances[$name] = $this->resolve($name);
            

            return $this->instances[$name];
        }

        return $this->resolve($name);
    }
277779
public function find(\Closure $closure)
    {
        foreach ($this->getGenerator() as $key => $value) {
            if ($closure($value, $key)) {
                return $value;
            }
        }

        return false;
    }
165036
public function getService($name)
    {
        $container = $this->getContainer();

        return !is_null($container) && isset($container[$name]) ? $container[$name] : null;
    }
215601
public function bind($name, \Closure $callable, $singleton = false)
    {
        $this->_ioc[$name] = array(
            'closure'   => $callable,
            'singleton' => (bool) $singleton,
            'instance'  => null
        );

        return $this;
    }