tomcizek/symfony-interop-container

Symfony Interop Container which has config array under 'config' key - for Extensions using Interoperability Factories.

1.1.0 2017-10-10 12:50 UTC

This package is not auto-updated.

Last update: 2024-04-16 16:58:48 UTC


README

Build Status Quality Score Code Coverage

This bundle is handy when you want to create symfony vendor bundle that uses interoperability factories with interop config.

Why bother?

It registers 'interop_container' service for you, which has same services as default 'service_container', plus it returns app config array under key 'config'. This config is something you need to define in your extension.

Quick start

1) Install this library through composer

composer require tomcizek/symfony-interop-container

2) Register SymfonyInteropContainerBundle in your kernel

3) Create your Bundle with Extension and register in kernel too, for example:

class TestExtension extends AbstractInteropExtension
{
	public function load(array $configs, ContainerBuilder $containerBuilder)
	{
		// parent call is mandatory, or it will not work as expected!
		parent::load($configs, $containerBuilder);

		// we can set another config key (default is extension alias: $this->getAlias())
		$this->configBuilder->setKey('test');

		// we can merge over another config
		$this->configBuilder->mergeOverByConfig([]);

		// we can merge over multiple configs
		$this->configBuilder->mergeOverByConfigs([[]]);

		// we can merge default config
		$this->configBuilder->mergeDefaultConfig([]);

		// if you want, you can build config by:
		$config = $this->configBuilder->build();

		// it will be built in process method and injected into interop_container service
	}

	public function process(ContainerBuilder $containerBuilder)
	{
		// If you need to redefine process method, parent call is mandatory.
		parent::process($containerBuilder);
	}
}

Contribute

Please feel free to fork and extend existing or add new features and send a pull request with your changes! To establish a consistent code quality, please provide unit tests for all your changes and may adapt the documentation.