W3cubDocs

/Symfony 4.1

RegisterMappingsPass

abstract class RegisterMappingsPass implements CompilerPassInterface

Base class for the doctrine bundles to provide a compiler pass class that helps to register doctrine mappings.

The compiler pass is meant to register the mappings with the metadata chain driver corresponding to one of the object managers.

For concrete implementations that are easy to use, see the RegisterXyMappingsPass classes in the DoctrineBundle resp. DoctrineMongodbBundle, DoctrineCouchdbBundle and DoctrinePhpcrBundle.

Properties

protected Definition|Reference $driver DI object for the driver to use, either a service definition for a private service or a reference for a public service.
protected string[] $namespaces List of namespaces handled by the driver.
protected string[] $managerParameters List of potential container parameters that hold the object manager name to register the mappings with the correct metadata driver, for example array('acme.manager', 'doctrine.default_entity_manager').
protected string $driverPattern Naming pattern of the metadata chain driver service ids, for example 'doctrine.orm.%s_metadata_driver'.
protected string|false $enabledParameter A name for a parameter in the container. If set, this compiler pass will only do anything if the parameter is present. (But regardless of the value of that parameter.

Methods

__construct(Definition|Reference $driver, array $namespaces, array $managerParameters, string $driverPattern, string|false $enabledParameter = false, string $configurationPattern = '', string $registerAliasMethodName = '', array $aliasMap = array())

The $managerParameters is an ordered list of container parameters that could provide the name of the manager to register these namespaces and alias on. The first non-empty name is used, the others skipped.

process(ContainerBuilder $container)

Register mappings and alias with the metadata drivers.

string getChainDriverServiceName(ContainerBuilder $container)

Get the service name of the metadata chain driver that the mappings should be registered with.

Definition|Reference getDriver(ContainerBuilder $container)

Create the service definition for the metadata driver.

bool enabled(ContainerBuilder $container)

Determine whether this mapping should be activated or not. This allows to take this decision with the container builder available.

Details

__construct(Definition|Reference $driver, array $namespaces, array $managerParameters, string $driverPattern, string|false $enabledParameter = false, string $configurationPattern = '', string $registerAliasMethodName = '', array $aliasMap = array())

The $managerParameters is an ordered list of container parameters that could provide the name of the manager to register these namespaces and alias on. The first non-empty name is used, the others skipped.

The $aliasMap parameter can be used to define bundle namespace shortcuts like the DoctrineBundle provides automatically for objects in the default Entity/Document folder.

Parameters

Definition|Reference $driver Driver DI definition or reference
array $namespaces List of namespaces handled by $driver
array $managerParameters list of container parameters that could hold the manager name
string $driverPattern Pattern for the metadata driver service name
string|false $enabledParameter Service container parameter that must be present to enable the mapping. Set to false to not do any check, optional.
string $configurationPattern Pattern for the Configuration service name
string $registerAliasMethodName Name of Configuration class method to register alias
array $aliasMap Map of alias to namespace

process(ContainerBuilder $container)

Register mappings and alias with the metadata drivers.

Parameters

ContainerBuilder $container

protected string getChainDriverServiceName(ContainerBuilder $container)

Get the service name of the metadata chain driver that the mappings should be registered with.

Parameters

ContainerBuilder $container

Return Value

string The name of the chain driver service

Exceptions

InvalidArgumentException if non of the managerParameters has a non-empty value

protected Definition|Reference getDriver(ContainerBuilder $container)

Create the service definition for the metadata driver.

Parameters

ContainerBuilder $container Passed on in case an extending class needs access to the container

Return Value

Definition|Reference the metadata driver to add to all chain drivers

protected bool enabled(ContainerBuilder $container)

Determine whether this mapping should be activated or not. This allows to take this decision with the container builder available.

This default implementation checks if the class has the enabledParameter configured and if so if that parameter is present in the container.

Parameters

ContainerBuilder $container

Return Value

bool whether this compiler pass really should register the mappings