src/ServiceContainer.php
protected function createFromFactory($factory)
    {
        try {
            if (is_string($factory) && class_exists($factory)) {
                $factory = new $factory();
            }

            if (is_callable($factory)) {
                $service  = $factory($this);
            } else {
                throw new ContainerException(
                    'Service could not be created: "There were incorrectly '
                        . 'transmitted data when registering the service".'
                );
            }
        } catch (ContainerException $e) {
            throw $e;
        } catch (\Throwable $e) {
            throw new ContainerException(
                'Service could not be created: "Service factory may be '
                    . 'callable or string (that can be resolving to an '
                    . 'invokable class or to a FactoryInterface instance).'
            );
        }

        return $service;
    }
protected function createFromFactory($factory)
    {
        try {
            if (is_string($factory) && class_exists($factory)) {
                $factory = new $factory();
            }

            if (is_callable($factory)) {
                $service  = $factory($this);
            } else {
                throw new ContainerException(
                    'Service could not be created: "There were incorrectly '
                        . 'transmitted data when registering the service".'
                );
            }
        } catch (ContainerException $e) {
            throw $e;
        } catch (\Throwable $e) {
            throw new ContainerException(
                'Service could not be created: "Service factory may be '
                    . 'callable or string (that can be resolving to an '
                    . 'invokable class or to a FactoryInterface instance).'
            );
        }

        return $service;
    }
protected function createFromFactory ( $ factory ) { try { if ( is_string ( $ factory ) && class_exists ( $ factory ) ) { $ factory = new $ factory ( ) ; } if ( is_callable ( $ factory ) ) { $ service = $ factory ( $ this ) ; } else { throw new ContainerException ( 'Service could not be created: "There were incorrectly ' . 'transmitted data when registering the service".' ) ; } } catch ( ContainerException $ e ) { throw $ e ; } catch ( \ Throwable $ e ) { throw new ContainerException ( 'Service could not be created: "Service factory may be ' . 'callable or string (that can be resolving to an ' . 'invokable class or to a FactoryInterface instance).' ) ; } return $ service ; }
Create a new instance of service from factory.

@param string|callable $factory The service factory.
@return mixed New service.
@throws ContainerException Error while service could not be created.
Create a new instance of service from factory .