Skip to content

kerasai/container-aware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Container Aware

This package adds utilities for making code "container aware".

Usage

To build a service container and automatically inject the container to all container aware services:

<?php

use Kerasai\ContainerAware\ContainerAwareCompilerPass;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

$containerBuilder = new ContainerBuilder();
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__));
$loader->load('services.yml');
$containerBuilder->addCompilerPass(new ContainerAwareCompilerPass());
$containerBuilder->compile();

And on your services, implement the \Symfony\Component\DependencyInjection\ContainerAwareInterface interface. Also use \Symfony\Component\DependencyInjection\ContainerAwareTrait to easily implement the interface.

About

Tooling inject container into services.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages