made DIC tags only available during "compilation"

Now that we have a compilation phase for the DIC, using tags after compilation
is not needed anymore.

Tags were introduced to allow several independant bundles to be able to
interact which each others (remember that each extension knows nothing about
the others).

But during the compilation phase, the container has been merged ans so, all
the information from all bundles are available. This is then the right place
to deal with tags. That way, less work is needed at runtime and the DIC class
in the cache is also much smaller.

For simple cases, it means that you need to process the tag in a compiler pass
and store the information you need in a DIC parameter (have a look at the
TranslatorPass for a very simple example).

So, the PHP dumper does not add tags to the dumped PHP class anymore (it does
not implements TaggedContainerInterface anymore). But tags are still available
on ContainerBuilder instances.
This commit is contained in:
Fabien Potencier 2011-01-17 11:40:04 +01:00
parent e0050dfc8f
commit c5f2ec8d2d
8 changed files with 8 additions and 171 deletions

View File

@ -75,7 +75,6 @@ class PhpDumper extends Dumper
$this->startClass($options['class'], $options['base_class']).
$this->addConstructor().
$this->addServices().
$this->addTags().
$this->addDefaultParametersMethod().
$this->addInterfaceInjectors().
$this->endClass()
@ -491,39 +490,6 @@ EOF;
return $publicServices.$aliasServices.$privateServices;
}
protected function addTags()
{
$tags = array();
foreach ($this->container->getDefinitions() as $id => $definition) {
foreach ($definition->getTags() as $name => $ann) {
if (!isset($tags[$name])) {
$tags[$name] = array();
}
$tags[$name][$id] = $ann;
}
}
$tags = $this->exportParameters($tags);
return <<<EOF
/**
* Returns service ids for a given tag.
*
* @param string \$name The tag name
*
* @return array An array of tags
*/
public function findTaggedServiceIds(\$name)
{
static \$tags = $tags;
return isset(\$tags[\$name]) ? \$tags[\$name] : array();
}
EOF;
}
protected function startClass($class, $baseClass)
{
$bagClass = $this->container->isFrozen() ? 'FrozenParameterBag' : 'ParameterBag';
@ -532,7 +498,6 @@ EOF;
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@ -544,7 +509,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\\$bagClass;
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class $class extends $baseClass implements TaggedContainerInterface
class $class extends $baseClass
{
EOF;
}

View File

@ -1,7 +1,6 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@ -13,7 +12,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class Container extends AbstractContainer implements TaggedContainerInterface
class Container extends AbstractContainer
{
/**
* Constructor.
@ -22,20 +21,4 @@ class Container extends AbstractContainer implements TaggedContainerInterface
{
parent::__construct(new ParameterBag($this->getDefaultParameters()));
}
/**
* Returns service ids for a given tag.
*
* @param string $name The tag name
*
* @return array An array of tags
*/
public function findTaggedServiceIds($name)
{
static $tags = array(
);
return isset($tags[$name]) ? $tags[$name] : array();
}
}

View File

@ -1,7 +1,6 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@ -13,7 +12,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container implements TaggedContainerInterface
class ProjectServiceContainer extends Container
{
/**
* Constructor.
@ -22,20 +21,4 @@ class ProjectServiceContainer extends Container implements TaggedContainerInterf
{
parent::__construct(new ParameterBag($this->getDefaultParameters()));
}
/**
* Returns service ids for a given tag.
*
* @param string $name The tag name
*
* @return array An array of tags
*/
public function findTaggedServiceIds($name)
{
static $tags = array(
);
return isset($tags[$name]) ? $tags[$name] : array();
}
}

View File

@ -1,7 +1,6 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@ -13,7 +12,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container implements TaggedContainerInterface
class ProjectServiceContainer extends Container
{
/**
* Constructor.
@ -23,22 +22,6 @@ class ProjectServiceContainer extends Container implements TaggedContainerInterf
parent::__construct(new ParameterBag($this->getDefaultParameters()));
}
/**
* Returns service ids for a given tag.
*
* @param string $name The tag name
*
* @return array An array of tags
*/
public function findTaggedServiceIds($name)
{
static $tags = array(
);
return isset($tags[$name]) ? $tags[$name] : array();
}
/**
* Gets the default parameters.
*

View File

@ -1,7 +1,6 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@ -13,7 +12,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container implements TaggedContainerInterface
class ProjectServiceContainer extends Container
{
/**
* Constructor.
@ -136,31 +135,6 @@ class ProjectServiceContainer extends Container implements TaggedContainerInterf
return $this->get('foo');
}
/**
* Returns service ids for a given tag.
*
* @param string $name The tag name
*
* @return array An array of tags
*/
public function findTaggedServiceIds($name)
{
static $tags = array(
'foo' => array(
'foo' => array(
0 => array(
'foo' => 'foo',
),
1 => array(
'bar' => 'bar',
),
),
),
);
return isset($tags[$name]) ? $tags[$name] : array();
}
/**
* Gets the default parameters.
*

View File

@ -1,7 +1,6 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@ -13,7 +12,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container implements TaggedContainerInterface
class ProjectServiceContainer extends Container
{
/**
* Constructor.
@ -40,22 +39,6 @@ class ProjectServiceContainer extends Container implements TaggedContainerInterf
return $instance;
}
/**
* Returns service ids for a given tag.
*
* @param string $name The tag name
*
* @return array An array of tags
*/
public function findTaggedServiceIds($name)
{
static $tags = array(
);
return isset($tags[$name]) ? $tags[$name] : array();
}
/**
* Gets the default parameters.
*

View File

@ -1,7 +1,6 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@ -13,7 +12,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container implements TaggedContainerInterface
class ProjectServiceContainer extends Container
{
/**
* Constructor.
@ -39,22 +38,6 @@ class ProjectServiceContainer extends Container implements TaggedContainerInterf
$this->applyInterfaceInjectors($instance);
}
/**
* Returns service ids for a given tag.
*
* @param string $name The tag name
*
* @return array An array of tags
*/
public function findTaggedServiceIds($name)
{
static $tags = array(
);
return isset($tags[$name]) ? $tags[$name] : array();
}
/**
* Gets the default parameters.
*

View File

@ -1,7 +1,6 @@
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
@ -13,7 +12,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container implements TaggedContainerInterface
class ProjectServiceContainer extends Container
{
/**
* Constructor.
@ -53,22 +52,6 @@ class ProjectServiceContainer extends Container implements TaggedContainerInterf
$this->applyInterfaceInjectors($instance);
}
/**
* Returns service ids for a given tag.
*
* @param string $name The tag name
*
* @return array An array of tags
*/
public function findTaggedServiceIds($name)
{
static $tags = array(
);
return isset($tags[$name]) ? $tags[$name] : array();
}
/**
* Applies all known interface injection calls
*