PHP Class DI\ContainerBuilder

With the default options, the container created is appropriate for the development environment. Example: $builder = new ContainerBuilder(); $container = $builder->build();
Since: 3.2
Author: Matthieu Napoli ([email protected])
Show file Open project: mnapoli/php-di Class Usage Examples

Public Methods

Method Description
__construct ( string $containerClass = 'DI\Container' )
addDefinitions ( string | array | DI\Definition\Source\DefinitionSource $definitions ) Add definitions to the container.
build ( ) : Container Build and return a container.
buildDevContainer ( ) : Container Build a container configured for the dev environment.
ignorePhpDocErrors ( boolean $bool ) : ContainerBuilder Enable or disable ignoring phpdoc errors (non-existent classes in @param or @var).
setDefinitionCache ( Doctrine\Common\Cache\Cache $cache ) : ContainerBuilder Enables the use of a cache for the definitions.
useAnnotations ( boolean $bool ) : ContainerBuilder Enable or disable the use of annotations to guess injections.
useAutowiring ( boolean $bool ) : ContainerBuilder Enable or disable the use of autowiring to guess injections.
wrapContainer ( Interop\Container\ContainerInterface $otherContainer ) If PHP-DI's container is wrapped by another container, we can set this so that PHP-DI will use the wrapper rather than itself for building objects.
writeProxiesToFile ( boolean $writeToFile, string | null $proxyDirectory = null ) : ContainerBuilder Configure the proxy generation.

Private Methods

Method Description
ensureNotLocked ( )

Method Details

__construct() public method

public __construct ( string $containerClass = 'DI\Container' )
$containerClass string Name of the container class, used to create the container.

addDefinitions() public method

Add definitions to the container.
public addDefinitions ( string | array | DI\Definition\Source\DefinitionSource $definitions )
$definitions string | array | DI\Definition\Source\DefinitionSource Can be an array of definitions, the name of a file containing definitions or a DefinitionSource object.

build() public method

Build and return a container.
public build ( ) : Container
return Container

buildDevContainer() public static method

Build a container configured for the dev environment.
public static buildDevContainer ( ) : Container
return Container

ignorePhpDocErrors() public method

Enable or disable ignoring phpdoc errors (non-existent classes in @param or @var).
public ignorePhpDocErrors ( boolean $bool ) : ContainerBuilder
$bool boolean
return ContainerBuilder

setDefinitionCache() public method

Enables the use of a cache for the definitions.
public setDefinitionCache ( Doctrine\Common\Cache\Cache $cache ) : ContainerBuilder
$cache Doctrine\Common\Cache\Cache Cache backend to use
return ContainerBuilder

useAnnotations() public method

Disabled by default.
public useAnnotations ( boolean $bool ) : ContainerBuilder
$bool boolean
return ContainerBuilder

useAutowiring() public method

Enabled by default.
public useAutowiring ( boolean $bool ) : ContainerBuilder
$bool boolean
return ContainerBuilder

wrapContainer() public method

If PHP-DI's container is wrapped by another container, we can set this so that PHP-DI will use the wrapper rather than itself for building objects.
public wrapContainer ( Interop\Container\ContainerInterface $otherContainer )
$otherContainer Interop\Container\ContainerInterface

writeProxiesToFile() public method

For dev environment, use writeProxiesToFile(false) (default configuration) For production environment, use writeProxiesToFile(true, 'tmp/proxies')
public writeProxiesToFile ( boolean $writeToFile, string | null $proxyDirectory = null ) : ContainerBuilder
$writeToFile boolean If true, write the proxies to disk to improve performances
$proxyDirectory string | null Directory where to write the proxies
return ContainerBuilder