Copied!

Container is a dependency injection container.

It gives access to object instances (services). Services and parameters are simple key/pair stores. The container can have four possible behaviors when a service does not exist (or is not initialized for the last case):

  • EXCEPTION_ON_INVALID_REFERENCE: Throws an exception at compilation time (the default)
  • NULL_ON_INVALID_REFERENCE: Returns null
  • IGNORE_ON_INVALID_REFERENCE: Ignores the wrapping command asking for the reference (for instance, ignore a setter if the service does not exist)
  • IGNORE_ON_UNINITIALIZED_REFERENCE: Ignores/returns null for uninitialized services or invalid references
  • RUNTIME_EXCEPTION_ON_INVALID_REFERENCE: Throws an exception at runtime
Instantiable
Constants
public Symfony\Component\DependencyInjection\ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE = 1
public Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_INVALID_REFERENCE = 3
public Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE = 4
public Symfony\Component\DependencyInjection\ContainerInterface::NULL_ON_INVALID_REFERENCE = 2
public Symfony\Component\DependencyInjection\ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE = 0
Methods
public __construct(?Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag = NULL)
public static camelize(string $id) : string
 

Camelizes a string.

public compile() : void
 

Compiles the container.

This method does two things:

  • Parameter values are resolved;
  • The parameter bag is frozen.
public get(string $id, int $invalidBehavior = 1self::EXCEPTION_ON_INVALID_REFERENCE) : ?object
 

Gets a service.

  • throws \ServiceCircularReferenceException When a circular reference is detected
  • throws \ServiceNotFoundException When the service is not defined
  • see \Reference
public getParameter(string $name) : UnitEnum|array|string|int|float|bool|?null
 

Gets a parameter.

  • throws \ParameterNotFoundException if the parameter is not defined
public getParameterBag() : Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface
 

Gets the service container parameter bag.

public getRemovedIds() : array
 

Gets service ids that existed at compile time.

public getServiceIds() : array
 

Gets all service ids.

  • return string[]
public has(string $id) : bool
public hasParameter(string $name) : bool
public initialized(string $id) : bool
 

Returns true if the given service has actually been initialized.

public isCompiled() : bool
 

Returns true if the container is compiled.

public reset() : void
public set(string $id, ?object $service) : void
 

Sets a service.

Setting a synthetic service to null resets it: has() returns false and get() behaves in the same way as if the service was never created.

public setParameter(string $name, UnitEnum|array|string|int|float|bool|?null $value) : void
public static underscore(string $id) : string
 

A string to underscore.

Properties
protected array $aliases = []
protected array $factories = []
protected array $fileMap = []
protected array $loading = []
protected array $methodMap = []
protected Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag
protected array $privates = []
protected array $resolving = []
protected array $services = []
protected array $syntheticIds = []
Methods
protected getEnv(string $name) : ?mixed
 

Fetches a variable from the environment.

  • throws \EnvNotFoundException When the environment variable is not found and has no default value
protected final getService(string|false $registry, string $id, ?string $method, string|bool $load) : ?mixed
 
  • internal
protected load(string $file) : ?mixed
 

Creates a service by requiring its factory file.

Properties
private bool $compiled = false
private array $envCache = []
private Closure $getEnv
private static Closure $make
Methods
private __clone()
private static make(self $container, string $id, int $invalidBehavior) : ?object
 

Creates a service.

As a separate method to allow "get()" to use the really fast ?? operator.

Properties
private static Closure $make
Methods
public static camelize(string $id) : string
 

Camelizes a string.

private static make(self $container, string $id, int $invalidBehavior) : ?object
 

Creates a service.

As a separate method to allow "get()" to use the really fast ?? operator.

public static underscore(string $id) : string
 

A string to underscore.

© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration