PHP code example of mouf / interop.symfony.di

1. Go to this page and download the library: Download mouf/interop.symfony.di library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mouf / interop.symfony.di example snippets


...

class AppKernel extends Kernel {
	...
	
	/**
	 * Gets the container's base class.
	 * We use this to make Symfony use the ExtensibleContainer.
	 *
	 * @return string
	 */
	protected function getContainerBaseClass()
	{
		return 'Mouf\\Symfony\\Component\\DependencyInjection\\ExtensibleContainer';
	}
	
	/**
	 * Initializes the service container.
	 *
	 * Use this method to initialize your own DI container and register it
	 * in Symfony DI container.
	 */
	protected function initializeContainer()
	{
		parent::initializeContainer();
	    	
		// Here, you can access the Symfony container using $this->container and register
		// your own container in it.
	
		$compositeContainer = new CompositeContainer();

		// The SF2 container does not implement the ContainerInterface interface
		// Therefore, it needs to be "acclimated".
    	$acclimator = new ContainerAcclimator();
    	$sfContainer = $this->container;
    	$sfContainer->setParentContainer($compositeContainer);
    	$acclimatedSfContainer = $acclimator->acclimate($this->container);
    	
    	$compositeContainer->addContainer($acclimatedSfContainer);
    	
    	// Now, let's add other containers.
    	// They must implement the ContainerInterface (and optionnally the ParentAwareContainerInterface)
    	$compositeContainer->addContainer(MoufManager::getMoufManager());
	}
}