src/Container.php
public function register(callable $inject) : void
    {
        $reflection = new ReflectionFunction($inject);
        $parameters = $reflection->getParameters();
        foreach ($parameters as $parameter) {
            $key = $parameter->name;
            $getter = function ($c) use ($reflection, $parameters, $key) {
                if (isset($c->delegate)) {
                    try {
                        return $c->delegate->get($key);
                    } catch (NotFoundExceptionInterface $e) {
                        // That's fine, we'll try our own container next.
                    }
                }
                $args = [];
                foreach ($parameters as $param) {
                    if (!$param->isPassedByReference()) {
                        $args[] = $c->get($param->name);
                    } else {
                        ${$param->name} = null;
                        $args[$param->name] =& ${$param->name};
                    }
                }
                $reflection->invokeArgs($args);
                foreach ($args as $found => $value) {
                    if (!is_numeric($found) && $found == $key) {
                        $c::$map[$found] = $value;
                    }
                }
                if (array_key_exists($key, $args)) {
                    return $args[$key];
                }
                throw new NotFoundException($key);
            };
            static::$map[$key] = new ReflectionFunction($getter);
        }
    }
public function register(callable $inject) : void
    {
        $reflection = new ReflectionFunction($inject);
        $parameters = $reflection->getParameters();
        foreach ($parameters as $parameter) {
            $key = $parameter->name;
            $getter = function ($c) use ($reflection, $parameters, $key) {
                if (isset($c->delegate)) {
                    try {
                        return $c->delegate->get($key);
                    } catch (NotFoundExceptionInterface $e) {
                        // That's fine, we'll try our own container next.
                    }
                }
                $args = [];
                foreach ($parameters as $param) {
                    if (!$param->isPassedByReference()) {
                        $args[] = $c->get($param->name);
                    } else {
                        ${$param->name} = null;
                        $args[$param->name] =& ${$param->name};
                    }
                }
                $reflection->invokeArgs($args);
                foreach ($args as $found => $value) {
                    if (!is_numeric($found) && $found == $key) {
                        $c::$map[$found] = $value;
                    }
                }
                if (array_key_exists($key, $args)) {
                    return $args[$key];
                }
                throw new NotFoundException($key);
            };
            static::$map[$key] = new ReflectionFunction($getter);
        }
    }
public function register ( callable $ inject ) : void { $ reflection = new ReflectionFunction ( $ inject ) ; $ parameters = $ reflection -> getParameters ( ) ; foreach ( $ parameters as $ parameter ) { $ key = $ parameter -> name ; $ getter = function ( $ c ) use ( $ reflection , $ parameters , $ key ) { if ( isset ( $ c -> delegate ) ) { try { return $ c -> delegate -> get ( $ key ) ; } catch ( NotFoundExceptionInterface $ e ) { // That's fine, we'll try our own container next. } } $ args = [ ] ; foreach ( $ parameters as $ param ) { if ( ! $ param -> isPassedByReference ( ) ) { $ args [ ] = $ c -> get ( $ param -> name ) ; } else { $ { $ param -> name } = null ; $ args [ $ param -> name ] = & $ { $ param -> name } ; } } $ reflection -> invokeArgs ( $ args ) ; foreach ( $ args as $ found => $ value ) { if ( ! is_numeric ( $ found ) && $ found == $ key ) { $ c :: $ map [ $ found ] = $ value ; } } if ( array_key_exists ( $ key , $ args ) ) { return $ args [ $ key ] ; } throw new NotFoundException ( $ key ) ; } ; static :: $ map [ $ key ] = new ReflectionFunction ( $ getter ) ; } }
Register a group of dependencies defined in the callable. Each referenced
argument should be assigned its designated value when invoked. Note that
invocation takes place only when a dependency is retrieved.

@param callable $inject A callable associating values with keys.
@return void
Register a group of dependencies defined in the callable . Each referenced argument should be assigned its designated value when invoked . Note that invocation takes place only when a dependency is retrieved .