private function dispatchLazily(array $boundClassesToBindingData, bool $run)
    {
        foreach ($boundClassesToBindingData as $boundClass => $bindingData) {
            $bootstrapperClass = $bindingData['bootstrapper'];
            $target = $bindingData['target'];

            $factory = function () use ($boundClass, $bootstrapperClass, $target, $run) {
                // To make sure this factory isn't used anymore to resolve the bound class, unbind it
                // Otherwise, we'd get into an infinite loop every time we tried to resolve it
                if ($target === null) {
                    $this->container->unbind($boundClass);
                } else {
                    $this->container->for($target, function (IContainer $container) use ($boundClass) {
                        $container->unbind($boundClass);
                    });
                }

                $bootstrapper = $this->bootstrapperResolver->resolve($bootstrapperClass);

                if (!in_array($bootstrapper, $this->bootstrapperObjects)) {
                    $this->bootstrapperObjects[] = $bootstrapper;
                }

                if (!isset($this->dispatchedBootstrappers[$bootstrapperClass])) {
                    $bootstrapper->registerBindings($this->container);

                    if ($run) {
                        $this->container->callMethod($bootstrapper, 'run', [], true);
                    }

                    $this->dispatchedBootstrappers[$bootstrapperClass] = true;
                }

                if ($target === null) {
                    return $this->container->resolve($boundClass);
                } else {
                    return $this->container->for($target, function (IContainer $container) use ($boundClass) {
                        return $container->resolve($boundClass);
                    });
                }
            };

            if ($target === null) {
                $this->container->bindFactory($boundClass, $factory);
            } else {
                $this->container->for($target, function (IContainer $container) use ($boundClass, $factory) {
                    $container->bindFactory($boundClass, $factory);
                });
            }
        }
    }
private function dispatchLazily(array $boundClassesToBindingData, bool $run)
    {
        foreach ($boundClassesToBindingData as $boundClass => $bindingData) {
            $bootstrapperClass = $bindingData['bootstrapper'];
            $target = $bindingData['target'];

            $factory = function () use ($boundClass, $bootstrapperClass, $target, $run) {
                // To make sure this factory isn't used anymore to resolve the bound class, unbind it
                // Otherwise, we'd get into an infinite loop every time we tried to resolve it
                if ($target === null) {
                    $this->container->unbind($boundClass);
                } else {
                    $this->container->for($target, function (IContainer $container) use ($boundClass) {
                        $container->unbind($boundClass);
                    });
                }

                $bootstrapper = $this->bootstrapperResolver->resolve($bootstrapperClass);

                if (!in_array($bootstrapper, $this->bootstrapperObjects)) {
                    $this->bootstrapperObjects[] = $bootstrapper;
                }

                if (!isset($this->dispatchedBootstrappers[$bootstrapperClass])) {
                    $bootstrapper->registerBindings($this->container);

                    if ($run) {
                        $this->container->callMethod($bootstrapper, 'run', [], true);
                    }

                    $this->dispatchedBootstrappers[$bootstrapperClass] = true;
                }

                if ($target === null) {
                    return $this->container->resolve($boundClass);
                } else {
                    return $this->container->for($target, function (IContainer $container) use ($boundClass) {
                        return $container->resolve($boundClass);
                    });
                }
            };

            if ($target === null) {
                $this->container->bindFactory($boundClass, $factory);
            } else {
                $this->container->for($target, function (IContainer $container) use ($boundClass, $factory) {
                    $container->bindFactory($boundClass, $factory);
                });
            }
        }
    }
private function dispatchLazily ( array $ boundClassesToBindingData , bool $ run ) { foreach ( $ boundClassesToBindingData as $ boundClass => $ bindingData ) { $ bootstrapperClass = $ bindingData [ 'bootstrapper' ] ; $ target = $ bindingData [ 'target' ] ; $ factory = function ( ) use ( $ boundClass , $ bootstrapperClass , $ target , $ run ) { // To make sure this factory isn't used anymore to resolve the bound class, unbind it // Otherwise, we'd get into an infinite loop every time we tried to resolve it if ( $ target === null ) { $ this -> container -> unbind ( $ boundClass ) ; } else { $ this -> container -> for ( $ target , function ( IContainer $ container ) use ( $ boundClass ) { $ container -> unbind ( $ boundClass ) ; } ) ; } $ bootstrapper = $ this -> bootstrapperResolver -> resolve ( $ bootstrapperClass ) ; if ( ! in_array ( $ bootstrapper , $ this -> bootstrapperObjects ) ) { $ this -> bootstrapperObjects [ ] = $ bootstrapper ; } if ( ! isset ( $ this -> dispatchedBootstrappers [ $ bootstrapperClass ] ) ) { $ bootstrapper -> registerBindings ( $ this -> container ) ; if ( $ run ) { $ this -> container -> callMethod ( $ bootstrapper , 'run' , [ ] , true ) ; } $ this -> dispatchedBootstrappers [ $ bootstrapperClass ] = true ; } if ( $ target === null ) { return $ this -> container -> resolve ( $ boundClass ) ; } else { return $ this -> container -> for ( $ target , function ( IContainer $ container ) use ( $ boundClass ) { return $ container -> resolve ( $ boundClass ) ; } ) ; } } ; if ( $ target === null ) { $ this -> container -> bindFactory ( $ boundClass , $ factory ) ; } else { $ this -> container -> for ( $ target , function ( IContainer $ container ) use ( $ boundClass , $ factory ) { $ container -> bindFactory ( $ boundClass , $ factory ) ; } ) ; } } }
Dispatches the registry lazily

@param array $boundClassesToBindingData The mapping of bound classes to their targets and bootstrappers
@param bool $run Whether or not to run the bootstrapper (deprecated)
@throws RuntimeException Thrown if there was a problem dispatching the bootstrappers
Dispatches the registry lazily