renamed annotation to tag in the DIC
This commit is contained in:
parent
8f21e5d918
commit
355ed9b5f9
@ -20,7 +20,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="doctrine.data_collector" class="%doctrine.data_collector.class%">
|
<service id="doctrine.data_collector" class="%doctrine.data_collector.class%">
|
||||||
<annotation name="data_collector" />
|
<tag name="data_collector" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
@ -81,7 +81,7 @@ class WebExtension extends Extension
|
|||||||
$loader->load('collectors.xml');
|
$loader->load('collectors.xml');
|
||||||
}
|
}
|
||||||
} elseif ($container->hasDefinition('profiler')) {
|
} elseif ($container->hasDefinition('profiler')) {
|
||||||
$container->getDefinition('profiling')->clearAnnotations();
|
$container->getDefinition('profiling')->clearTags();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ class WebExtension extends Extension
|
|||||||
$loader->load('toolbar.xml');
|
$loader->load('toolbar.xml');
|
||||||
}
|
}
|
||||||
} elseif ($container->hasDefinition('debug.toolbar')) {
|
} elseif ($container->hasDefinition('debug.toolbar')) {
|
||||||
$container->getDefinition('debug.toolbar')->clearAnnotations();
|
$container->getDefinition('debug.toolbar')->clearTags();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ class WebExtension extends Extension
|
|||||||
$loader->setArguments($arguments);
|
$loader->setArguments($arguments);
|
||||||
}
|
}
|
||||||
} elseif ($container->hasDefinition('validator')) {
|
} elseif ($container->hasDefinition('validator')) {
|
||||||
$container->getDefinition('validator')->clearAnnotations();
|
$container->getDefinition('validator')->clearTags();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class Profiler extends BaseProfiler
|
|||||||
|
|
||||||
protected function initCollectors()
|
protected function initCollectors()
|
||||||
{
|
{
|
||||||
$config = $this->container->findAnnotatedServiceIds('data_collector');
|
$config = $this->container->findTaggedServiceIds('data_collector');
|
||||||
$ids = array();
|
$ids = array();
|
||||||
$coreCollectors = array();
|
$coreCollectors = array();
|
||||||
$userCollectors = array();
|
$userCollectors = array();
|
||||||
|
@ -13,22 +13,22 @@
|
|||||||
|
|
||||||
<services>
|
<services>
|
||||||
<service id="data_collector.config" class="%data_collector.config.class%">
|
<service id="data_collector.config" class="%data_collector.config.class%">
|
||||||
<annotation name="data_collector" core="true" />
|
<tag name="data_collector" core="true" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="data_collector.app" class="%data_collector.app.class%">
|
<service id="data_collector.app" class="%data_collector.app.class%">
|
||||||
<annotation name="data_collector" core="true" />
|
<tag name="data_collector" core="true" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="data_collector.timer" class="%data_collector.timer.class%">
|
<service id="data_collector.timer" class="%data_collector.timer.class%">
|
||||||
<annotation name="data_collector" core="true" />
|
<tag name="data_collector" core="true" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="data_collector.memory" class="%data_collector.memory.class%">
|
<service id="data_collector.memory" class="%data_collector.memory.class%">
|
||||||
<annotation name="data_collector" core="true" />
|
<tag name="data_collector" core="true" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="profiler_listener" class="%profiler_listener.class%">
|
<service id="profiler_listener" class="%profiler_listener.class%">
|
||||||
<annotation name="kernel.listener" />
|
<tag name="kernel.listener" />
|
||||||
<argument type="service" id="profiler" />
|
<argument type="service" id="profiler" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
@ -19,17 +19,17 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="routing.loader.xml" class="%routing.loader.xml.class%">
|
<service id="routing.loader.xml" class="%routing.loader.xml.class%">
|
||||||
<annotation name="routing.loader" />
|
<tag name="routing.loader" />
|
||||||
<argument>%kernel.bundle_dirs%</argument>
|
<argument>%kernel.bundle_dirs%</argument>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="routing.loader.yml" class="%routing.loader.yml.class%">
|
<service id="routing.loader.yml" class="%routing.loader.yml.class%">
|
||||||
<annotation name="routing.loader" />
|
<tag name="routing.loader" />
|
||||||
<argument>%kernel.bundle_dirs%</argument>
|
<argument>%kernel.bundle_dirs%</argument>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="routing.loader.php" class="%routing.loader.php.class%">
|
<service id="routing.loader.php" class="%routing.loader.php.class%">
|
||||||
<annotation name="routing.loader" />
|
<tag name="routing.loader" />
|
||||||
<argument>%kernel.bundle_dirs%</argument>
|
<argument>%kernel.bundle_dirs%</argument>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
@ -46,43 +46,43 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="templating.helper.javascripts" class="%templating.helper.javascripts.class%">
|
<service id="templating.helper.javascripts" class="%templating.helper.javascripts.class%">
|
||||||
<annotation name="templating.helper" alias="javascripts" />
|
<tag name="templating.helper" alias="javascripts" />
|
||||||
<argument type="service" id="templating.helper.assets" />
|
<argument type="service" id="templating.helper.assets" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="templating.helper.stylesheets" class="%templating.helper.stylesheets.class%">
|
<service id="templating.helper.stylesheets" class="%templating.helper.stylesheets.class%">
|
||||||
<annotation name="templating.helper" alias="stylesheets" />
|
<tag name="templating.helper" alias="stylesheets" />
|
||||||
<argument type="service" id="templating.helper.assets" />
|
<argument type="service" id="templating.helper.assets" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="templating.helper.slots" class="%templating.helper.slots.class%">
|
<service id="templating.helper.slots" class="%templating.helper.slots.class%">
|
||||||
<annotation name="templating.helper" alias="slots" />
|
<tag name="templating.helper" alias="slots" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="templating.helper.assets" class="%templating.helper.assets.class%">
|
<service id="templating.helper.assets" class="%templating.helper.assets.class%">
|
||||||
<annotation name="templating.helper" alias="assets" />
|
<tag name="templating.helper" alias="assets" />
|
||||||
<argument type="service" id="request" />
|
<argument type="service" id="request" />
|
||||||
<argument />
|
<argument />
|
||||||
<argument>%templating.assets.version%</argument>
|
<argument>%templating.assets.version%</argument>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="templating.helper.request" class="%templating.helper.request.class%">
|
<service id="templating.helper.request" class="%templating.helper.request.class%">
|
||||||
<annotation name="templating.helper" alias="request" />
|
<tag name="templating.helper" alias="request" />
|
||||||
<argument type="service" id="request" />
|
<argument type="service" id="request" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="templating.helper.session" class="%templating.helper.session.class%">
|
<service id="templating.helper.session" class="%templating.helper.session.class%">
|
||||||
<annotation name="templating.helper" alias="session" />
|
<tag name="templating.helper" alias="session" />
|
||||||
<argument type="service" id="request" />
|
<argument type="service" id="request" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="templating.helper.router" class="%templating.helper.router.class%">
|
<service id="templating.helper.router" class="%templating.helper.router.class%">
|
||||||
<annotation name="templating.helper" alias="router" />
|
<tag name="templating.helper" alias="router" />
|
||||||
<argument type="service" id="router" />
|
<argument type="service" id="router" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="templating.helper.actions" class="%templating.helper.actions.class%">
|
<service id="templating.helper.actions" class="%templating.helper.actions.class%">
|
||||||
<annotation name="templating.helper" alias="actions" />
|
<tag name="templating.helper" alias="actions" />
|
||||||
<argument type="service" id="controller_resolver" />
|
<argument type="service" id="controller_resolver" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<services>
|
<services>
|
||||||
<service id="debug.toolbar" class="%debug.toolbar.class%">
|
<service id="debug.toolbar" class="%debug.toolbar.class%">
|
||||||
<annotation name="kernel.listener" />
|
<tag name="kernel.listener" />
|
||||||
<argument type="service" id="profiler" />
|
<argument type="service" id="profiler" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="request_listener" class="%request_listener.class%">
|
<service id="request_listener" class="%request_listener.class%">
|
||||||
<annotation name="kernel.listener" />
|
<tag name="kernel.listener" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
<argument type="service" id="router" />
|
<argument type="service" id="router" />
|
||||||
<argument type="service" id="logger" on-invalid="ignore" />
|
<argument type="service" id="logger" on-invalid="ignore" />
|
||||||
@ -30,16 +30,16 @@
|
|||||||
<service id="esi" class="%esi.class%" />
|
<service id="esi" class="%esi.class%" />
|
||||||
|
|
||||||
<service id="esi_listener" class="%esi_listener.class%">
|
<service id="esi_listener" class="%esi_listener.class%">
|
||||||
<annotation name="kernel.listener" />
|
<tag name="kernel.listener" />
|
||||||
<argument type="service" id="esi" on-invalid="ignore" />
|
<argument type="service" id="esi" on-invalid="ignore" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="response_listener" class="%response_listener.class%">
|
<service id="response_listener" class="%response_listener.class%">
|
||||||
<annotation name="kernel.listener" />
|
<tag name="kernel.listener" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="exception_listener" class="%exception_listener.class%">
|
<service id="exception_listener" class="%exception_listener.class%">
|
||||||
<annotation name="kernel.listener" />
|
<tag name="kernel.listener" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
<argument type="service" id="logger" on-invalid="null" />
|
<argument type="service" id="logger" on-invalid="null" />
|
||||||
<argument>%exception_listener.controller%</argument>
|
<argument>%exception_listener.controller%</argument>
|
||||||
|
@ -39,7 +39,7 @@ class LoaderResolver extends BaseLoaderResolver
|
|||||||
parent::__construct($loaders);
|
parent::__construct($loaders);
|
||||||
|
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
foreach ($container->findAnnotatedServiceIds('routing.loader') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('routing.loader') as $id => $attributes) {
|
||||||
$this->services[] = $id;
|
$this->services[] = $id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class Engine extends BaseEngine
|
|||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
$this->escaper = $escaper;
|
$this->escaper = $escaper;
|
||||||
|
|
||||||
foreach ($this->container->findAnnotatedServiceIds('templating.renderer') as $id => $attributes) {
|
foreach ($this->container->findTaggedServiceIds('templating.renderer') as $id => $attributes) {
|
||||||
if (isset($attributes[0]['alias'])) {
|
if (isset($attributes[0]['alias'])) {
|
||||||
$renderers[$attributes[0]['alias']] = $this->container->get($id);
|
$renderers[$attributes[0]['alias']] = $this->container->get($id);
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ class Engine extends BaseEngine
|
|||||||
parent::__construct($loader, $renderers);
|
parent::__construct($loader, $renderers);
|
||||||
|
|
||||||
$this->helpers = array();
|
$this->helpers = array();
|
||||||
foreach ($this->container->findAnnotatedServiceIds('templating.helper') as $id => $attributes) {
|
foreach ($this->container->findTaggedServiceIds('templating.helper') as $id => $attributes) {
|
||||||
if (isset($attributes[0]['alias'])) {
|
if (isset($attributes[0]['alias'])) {
|
||||||
$this->helpers[$attributes[0]['alias']] = $id;
|
$this->helpers[$attributes[0]['alias']] = $id;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class Environment extends \Twig_Environment
|
|||||||
{
|
{
|
||||||
parent::__construct($loader, $options);
|
parent::__construct($loader, $options);
|
||||||
|
|
||||||
foreach ($container->findAnnotatedServiceIds('twig.extension') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('twig.extension') as $id => $attributes) {
|
||||||
$this->addExtension($container->get($id));
|
$this->addExtension($container->get($id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,16 +29,16 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.renderer" class="%twig.renderer.class%">
|
<service id="twig.renderer" class="%twig.renderer.class%">
|
||||||
<annotation name="templating.renderer" alias="twig" />
|
<tag name="templating.renderer" alias="twig" />
|
||||||
<argument type="service" id="twig" />
|
<argument type="service" id="twig" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.extension.escaper" class="Twig_Extension_Escaper">
|
<service id="twig.extension.escaper" class="Twig_Extension_Escaper">
|
||||||
<annotation name="twig.extension" />
|
<tag name="twig.extension" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.extension.helpers" class="Symfony\Bundle\TwigBundle\Extension\Helpers">
|
<service id="twig.extension.helpers" class="Symfony\Bundle\TwigBundle\Extension\Helpers">
|
||||||
<annotation name="twig.extension" />
|
<tag name="twig.extension" />
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -20,7 +20,7 @@ use Symfony\Components\DependencyInjection\Resource\FileResource;
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
*/
|
*/
|
||||||
class ContainerBuilder extends Container implements AnnotatedContainerInterface
|
class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||||
{
|
{
|
||||||
static protected $extensions = array();
|
static protected $extensions = array();
|
||||||
|
|
||||||
@ -570,22 +570,22 @@ class ContainerBuilder extends Container implements AnnotatedContainerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns service ids for a given annotation.
|
* Returns service ids for a given tag.
|
||||||
*
|
*
|
||||||
* @param string $name The annotation name
|
* @param string $name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of annotations
|
* @return array An array of tags
|
||||||
*/
|
*/
|
||||||
public function findAnnotatedServiceIds($name)
|
public function findTaggedServiceIds($name)
|
||||||
{
|
{
|
||||||
$annotations = array();
|
$tags = array();
|
||||||
foreach ($this->getDefinitions() as $id => $definition) {
|
foreach ($this->getDefinitions() as $id => $definition) {
|
||||||
if ($definition->getAnnotation($name)) {
|
if ($definition->getTag($name)) {
|
||||||
$annotations[$id] = $definition->getAnnotation($name);
|
$tags[$id] = $definition->getTag($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $annotations;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function getServiceConditionals($value)
|
static public function getServiceConditionals($value)
|
||||||
|
@ -26,7 +26,7 @@ class Definition
|
|||||||
protected $arguments;
|
protected $arguments;
|
||||||
protected $calls;
|
protected $calls;
|
||||||
protected $configurator;
|
protected $configurator;
|
||||||
protected $annotations;
|
protected $tags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -40,7 +40,7 @@ class Definition
|
|||||||
$this->arguments = $arguments;
|
$this->arguments = $arguments;
|
||||||
$this->calls = array();
|
$this->calls = array();
|
||||||
$this->shared = true;
|
$this->shared = true;
|
||||||
$this->annotations = array();
|
$this->tags = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,58 +196,58 @@ class Definition
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all annotations.
|
* Returns all tags.
|
||||||
*
|
*
|
||||||
* @return array An array of annotations
|
* @return array An array of tags
|
||||||
*/
|
*/
|
||||||
public function getAnnotations()
|
public function getTags()
|
||||||
{
|
{
|
||||||
return $this->annotations;
|
return $this->tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an annotation by name.
|
* Gets a tag by name.
|
||||||
*
|
*
|
||||||
* @param string $name The annotation name
|
* @param string $name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of attributes
|
* @return array An array of attributes
|
||||||
*/
|
*/
|
||||||
public function getAnnotation($name)
|
public function getTag($name)
|
||||||
{
|
{
|
||||||
if (!isset($this->annotations[$name])) {
|
if (!isset($this->tags[$name])) {
|
||||||
$this->annotations[$name] = array();
|
$this->tags[$name] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->annotations[$name];
|
return $this->tags[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an annotation for this definition.
|
* Adds a tag for this definition.
|
||||||
*
|
*
|
||||||
* @param string $name The annotation name
|
* @param string $name The tag name
|
||||||
* @param array $attributes An array of attributes
|
* @param array $attributes An array of attributes
|
||||||
*
|
*
|
||||||
* @return Definition The current instance
|
* @return Definition The current instance
|
||||||
*/
|
*/
|
||||||
public function addAnnotation($name, array $attributes = array())
|
public function addTag($name, array $attributes = array())
|
||||||
{
|
{
|
||||||
if (!isset($this->annotations[$name])) {
|
if (!isset($this->tags[$name])) {
|
||||||
$this->annotations[$name] = array();
|
$this->tags[$name] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->annotations[$name][] = $attributes;
|
$this->tags[$name][] = $attributes;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the annotation for this definition.
|
* Clears the tags for this definition.
|
||||||
*
|
*
|
||||||
* @return Definition The current instance
|
* @return Definition The current instance
|
||||||
*/
|
*/
|
||||||
public function clearAnnotations()
|
public function clearTags()
|
||||||
{
|
{
|
||||||
$this->annotations = array();
|
$this->tags = array();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class PhpDumper extends Dumper
|
|||||||
$this->startClass($options['class'], $options['base_class']).
|
$this->startClass($options['class'], $options['base_class']).
|
||||||
$this->addConstructor().
|
$this->addConstructor().
|
||||||
$this->addServices().
|
$this->addServices().
|
||||||
$this->addAnnotations().
|
$this->addTags().
|
||||||
$this->addDefaultParametersMethod().
|
$this->addDefaultParametersMethod().
|
||||||
$this->endClass()
|
$this->endClass()
|
||||||
;
|
;
|
||||||
@ -229,34 +229,34 @@ EOF;
|
|||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addAnnotations()
|
protected function addTags()
|
||||||
{
|
{
|
||||||
$annotations = array();
|
$tags = array();
|
||||||
foreach ($this->container->getDefinitions() as $id => $definition) {
|
foreach ($this->container->getDefinitions() as $id => $definition) {
|
||||||
foreach ($definition->getAnnotations() as $name => $ann) {
|
foreach ($definition->getTags() as $name => $ann) {
|
||||||
if (!isset($annotations[$name])) {
|
if (!isset($tags[$name])) {
|
||||||
$annotations[$name] = array();
|
$tags[$name] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$annotations[$name][$id] = $ann;
|
$tags[$name][$id] = $ann;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$annotations = var_export($annotations, true);
|
$tags = var_export($tags, true);
|
||||||
|
|
||||||
return <<<EOF
|
return <<<EOF
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns service ids for a given annotation.
|
* Returns service ids for a given tag.
|
||||||
*
|
*
|
||||||
* @param string \$name The annotation name
|
* @param string \$name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of annotations
|
* @return array An array of tags
|
||||||
*/
|
*/
|
||||||
public function findAnnotatedServiceIds(\$name)
|
public function findTaggedServiceIds(\$name)
|
||||||
{
|
{
|
||||||
static \$annotations = $annotations;
|
static \$tags = $tags;
|
||||||
|
|
||||||
return isset(\$annotations[\$name]) ? \$annotations[\$name] : array();
|
return isset(\$tags[\$name]) ? \$tags[\$name] : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
|
@ -59,15 +59,15 @@ class XmlDumper extends Dumper
|
|||||||
!$definition->isShared() ? ' shared="false"' : ''
|
!$definition->isShared() ? ' shared="false"' : ''
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($definition->getAnnotations() as $name => $annotations) {
|
foreach ($definition->getTags() as $name => $tags) {
|
||||||
foreach ($annotations as $attributes) {
|
foreach ($tags as $attributes) {
|
||||||
$att = array();
|
$att = array();
|
||||||
foreach ($attributes as $key => $value) {
|
foreach ($attributes as $key => $value) {
|
||||||
$att[] = sprintf('%s="%s"', $key, $value);
|
$att[] = sprintf('%s="%s"', $key, $value);
|
||||||
}
|
}
|
||||||
$att = $att ? ' '.implode(' ', $att) : '';
|
$att = $att ? ' '.implode(' ', $att) : '';
|
||||||
|
|
||||||
$code .= sprintf(" <annotation name=\"%s\"%s />\n", $name, $att);
|
$code .= sprintf(" <tag name=\"%s\"%s />\n", $name, $att);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,20 +42,20 @@ class YamlDumper extends Dumper
|
|||||||
$code .= sprintf(" class: %s\n", $definition->getClass());
|
$code .= sprintf(" class: %s\n", $definition->getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
$annotationsCode = '';
|
$tagsCode = '';
|
||||||
foreach ($definition->getAnnotations() as $name => $annotations) {
|
foreach ($definition->getTags() as $name => $tags) {
|
||||||
foreach ($annotations as $attributes) {
|
foreach ($tags as $attributes) {
|
||||||
$att = array();
|
$att = array();
|
||||||
foreach ($attributes as $key => $value) {
|
foreach ($attributes as $key => $value) {
|
||||||
$att[] = sprintf('%s: %s', Yaml::dump($key), Yaml::dump($value));
|
$att[] = sprintf('%s: %s', Yaml::dump($key), Yaml::dump($value));
|
||||||
}
|
}
|
||||||
$att = $att ? ', '.implode(' ', $att) : '';
|
$att = $att ? ', '.implode(' ', $att) : '';
|
||||||
|
|
||||||
$annotationsCode .= sprintf(" - { name: %s%s }\n", Yaml::dump($name), $att);
|
$tagsCode .= sprintf(" - { name: %s%s }\n", Yaml::dump($name), $att);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($annotationsCode) {
|
if ($tagsCode) {
|
||||||
$code .= " annotations:\n".$annotationsCode;
|
$code .= " tags:\n".$tagsCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($definition->getFile()) {
|
if ($definition->getFile()) {
|
||||||
|
@ -138,9 +138,9 @@ class XmlFileLoader extends FileLoader
|
|||||||
$definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument'));
|
$definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument'));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($service->annotation as $annotation) {
|
foreach ($service->tag as $tag) {
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
foreach ($annotation->attributes() as $name => $value) {
|
foreach ($tag->attributes() as $name => $value) {
|
||||||
if ('name' === $name) {
|
if ('name' === $name) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
$parameters[$name] = SimpleXMLElement::phpize($value);
|
$parameters[$name] = SimpleXMLElement::phpize($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$definition->addAnnotation((string) $annotation['name'], $parameters);
|
$definition->addTag((string) $tag['name'], $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->container->setDefinition($id, $definition);
|
$this->container->setDefinition($id, $definition);
|
||||||
|
@ -144,12 +144,12 @@ class YamlFileLoader extends FileLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($service['annotations'])) {
|
if (isset($service['tags'])) {
|
||||||
foreach ($service['annotations'] as $annotation) {
|
foreach ($service['tags'] as $tag) {
|
||||||
$name = $annotation['name'];
|
$name = $tag['name'];
|
||||||
unset($annotation['name']);
|
unset($tag['name']);
|
||||||
|
|
||||||
$definition->addAnnotation($name, $annotation);
|
$definition->addTag($name, $tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@
|
|||||||
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
|
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
|
||||||
<xsd:element name="configurator" type="configurator" minOccurs="0" maxOccurs="1" />
|
<xsd:element name="configurator" type="configurator" minOccurs="0" maxOccurs="1" />
|
||||||
<xsd:element name="call" type="call" minOccurs="0" maxOccurs="unbounded" />
|
<xsd:element name="call" type="call" minOccurs="0" maxOccurs="unbounded" />
|
||||||
<xsd:element name="annotation" type="annotation" minOccurs="0" maxOccurs="unbounded" />
|
<xsd:element name="tag" type="tag" minOccurs="0" maxOccurs="unbounded" />
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
<xsd:attribute name="id" type="xsd:string" />
|
<xsd:attribute name="id" type="xsd:string" />
|
||||||
<xsd:attribute name="class" type="xsd:string" />
|
<xsd:attribute name="class" type="xsd:string" />
|
||||||
@ -94,7 +94,7 @@
|
|||||||
<xsd:attribute name="alias" type="xsd:string" />
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="annotation">
|
<xsd:complexType name="tag">
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
<xsd:anyAttribute namespace="##any" processContents="lax" />
|
<xsd:anyAttribute namespace="##any" processContents="lax" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
@ -12,18 +12,18 @@ namespace Symfony\Components\DependencyInjection;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AnnotatedContainerInterface is the interface implemented when a container knows how to deals with annotations.
|
* TaggedContainerInterface is the interface implemented when a container knows how to deals with tags.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||||
*/
|
*/
|
||||||
interface AnnotatedContainerInterface
|
interface TaggedContainerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns service ids for a given annotation.
|
* Returns service ids for a given tag.
|
||||||
*
|
*
|
||||||
* @param string $name The annotation name
|
* @param string $name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of annotations
|
* @return array An array of tags
|
||||||
*/
|
*/
|
||||||
public function findAnnotatedServiceIds($name);
|
public function findTaggedServiceIds($name);
|
||||||
}
|
}
|
@ -28,7 +28,7 @@ class EventDispatcher extends BaseEventDispatcher
|
|||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
foreach ($container->findAnnotatedServiceIds('kernel.listener') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('kernel.listener') as $id => $attributes) {
|
||||||
$container->get($id)->register($this);
|
$container->get($id)->register($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ class KernelExtension extends Extension
|
|||||||
$container->setParameter('session.class', $config['class']);
|
$container->setParameter('session.class', $config['class']);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array('name', 'auto_start', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'pdo.db_table') as $name) {
|
foreach (array('name', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'pdo.db_table') as $name) {
|
||||||
if (isset($config['session'][$name])) {
|
if (isset($config['session'][$name])) {
|
||||||
$container->setParameter('session.options.'.$name, $config['session'][$name]);
|
$container->setParameter('session.options.'.$name, $config['session'][$name]);
|
||||||
}
|
}
|
||||||
@ -438,7 +438,7 @@ class EventDispatcher extends BaseEventDispatcher
|
|||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
foreach ($container->findAnnotatedServiceIds('kernel.listener') as $id => $attributes) {
|
foreach ($container->findTaggedServiceIds('kernel.listener') as $id => $attributes) {
|
||||||
$container->get($id)->register($this);
|
$container->get($id)->register($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,24 +341,24 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::findAnnotatedServiceIds
|
* @covers Symfony\Components\DependencyInjection\ContainerBuilder::findTaggedServiceIds
|
||||||
*/
|
*/
|
||||||
public function testFindAnnotatedServiceIds()
|
public function testfindTaggedServiceIds()
|
||||||
{
|
{
|
||||||
$builder = new ContainerBuilder();
|
$builder = new ContainerBuilder();
|
||||||
$builder
|
$builder
|
||||||
->register('foo', 'FooClass')
|
->register('foo', 'FooClass')
|
||||||
->addAnnotation('foo', array('foo' => 'foo'))
|
->addTag('foo', array('foo' => 'foo'))
|
||||||
->addAnnotation('bar', array('bar' => 'bar'))
|
->addTag('bar', array('bar' => 'bar'))
|
||||||
->addAnnotation('foo', array('foofoo' => 'foofoo'))
|
->addTag('foo', array('foofoo' => 'foofoo'))
|
||||||
;
|
;
|
||||||
$this->assertEquals($builder->findAnnotatedServiceIds('foo'), array(
|
$this->assertEquals($builder->findTaggedServiceIds('foo'), array(
|
||||||
'foo' => array(
|
'foo' => array(
|
||||||
array('foo' => 'foo'),
|
array('foo' => 'foo'),
|
||||||
array('foofoo' => 'foofoo'),
|
array('foofoo' => 'foofoo'),
|
||||||
)
|
)
|
||||||
), '->findAnnotatedServiceIds() returns an array of service ids and its annotation attributes');
|
), '->findTaggedServiceIds() returns an array of service ids and its tag attributes');
|
||||||
$this->assertEquals(array(), $builder->findAnnotatedServiceIds('foobar'), '->findAnnotatedServiceIds() returns an empty array if there is annotated services');
|
$this->assertEquals(array(), $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,34 +118,34 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Definition::clearAnnotations
|
* @covers Symfony\Components\DependencyInjection\Definition::clearTags
|
||||||
*/
|
*/
|
||||||
public function testClearAnnotations()
|
public function testClearTags()
|
||||||
{
|
{
|
||||||
$def = new Definition('stdClass');
|
$def = new Definition('stdClass');
|
||||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->clearAnnotations()), '->clearAnnotations() implements a fluent interface');
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->clearTags()), '->clearTags() implements a fluent interface');
|
||||||
$def->addAnnotation('foo', array('foo' => 'bar'));
|
$def->addTag('foo', array('foo' => 'bar'));
|
||||||
$def->clearAnnotations();
|
$def->clearTags();
|
||||||
$this->assertEquals(array(), $def->getAnnotations(), '->clearAnnotations() removes all current annotations');
|
$this->assertEquals(array(), $def->getTags(), '->clearTags() removes all current tags');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Components\DependencyInjection\Definition::addAnnotation
|
* @covers Symfony\Components\DependencyInjection\Definition::addTag
|
||||||
* @covers Symfony\Components\DependencyInjection\Definition::getAnnotation
|
* @covers Symfony\Components\DependencyInjection\Definition::getTag
|
||||||
* @covers Symfony\Components\DependencyInjection\Definition::getAnnotations
|
* @covers Symfony\Components\DependencyInjection\Definition::getTags
|
||||||
*/
|
*/
|
||||||
public function testAnnotations()
|
public function testTags()
|
||||||
{
|
{
|
||||||
$def = new Definition('stdClass');
|
$def = new Definition('stdClass');
|
||||||
$this->assertEquals(array(), $def->getAnnotation('foo'), '->getAnnotation() returns an empty array if the annotation is not defined');
|
$this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined');
|
||||||
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->addAnnotation('foo')), '->addAnnotation() implements a fluent interface');
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->addTag('foo')), '->addTag() implements a fluent interface');
|
||||||
$this->assertEquals(array(array()), $def->getAnnotation('foo'), '->getAnnotation() returns attributes for an annotation name');
|
$this->assertEquals(array(array()), $def->getTag('foo'), '->getTag() returns attributes for a tag name');
|
||||||
$def->addAnnotation('foo', array('foo' => 'bar'));
|
$def->addTag('foo', array('foo' => 'bar'));
|
||||||
$this->assertEquals(array(array(), array('foo' => 'bar')), $def->getAnnotation('foo'), '->addAnnotation() can adds the same annotation several times');
|
$this->assertEquals(array(array(), array('foo' => 'bar')), $def->getTag('foo'), '->addTag() can adds the same tag several times');
|
||||||
$def->addAnnotation('bar', array('bar' => 'bar'));
|
$def->addTag('bar', array('bar' => 'bar'));
|
||||||
$this->assertEquals($def->getAnnotations(), array(
|
$this->assertEquals($def->getTags(), array(
|
||||||
'foo' => array(array(), array('foo' => 'bar')),
|
'foo' => array(array(), array('foo' => 'bar')),
|
||||||
'bar' => array(array('bar' => 'bar')),
|
'bar' => array(array('bar' => 'bar')),
|
||||||
), '->getAnnotations() returns all annotations');
|
), '->getTags() returns all tags');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ use Symfony\Components\DependencyInjection\Parameter;
|
|||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
$container->
|
$container->
|
||||||
register('foo', 'FooClass')->
|
register('foo', 'FooClass')->
|
||||||
addAnnotation('foo', array('foo' => 'foo'))->
|
addTag('foo', array('foo' => 'foo'))->
|
||||||
addAnnotation('foo', array('bar' => 'bar'))->
|
addTag('foo', array('bar' => 'bar'))->
|
||||||
setFactoryMethod('getInstance')->
|
setFactoryMethod('getInstance')->
|
||||||
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, new Reference('service_container')))->
|
setArguments(array('foo', new Reference('foo.baz'), array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, new Reference('service_container')))->
|
||||||
setFile(realpath(__DIR__.'/../includes/foo.php'))->
|
setFile(realpath(__DIR__.'/../includes/foo.php'))->
|
||||||
|
@ -25,17 +25,17 @@ class Container extends AbstractContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns service ids for a given annotation.
|
* Returns service ids for a given tag.
|
||||||
*
|
*
|
||||||
* @param string $name The annotation name
|
* @param string $name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of annotations
|
* @return array An array of tags
|
||||||
*/
|
*/
|
||||||
public function findAnnotatedServiceIds($name)
|
public function findTaggedServiceIds($name)
|
||||||
{
|
{
|
||||||
static $annotations = array (
|
static $tags = array (
|
||||||
);
|
);
|
||||||
|
|
||||||
return isset($annotations[$name]) ? $annotations[$name] : array();
|
return isset($tags[$name]) ? $tags[$name] : array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,17 +25,17 @@ class ProjectServiceContainer extends Container
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns service ids for a given annotation.
|
* Returns service ids for a given tag.
|
||||||
*
|
*
|
||||||
* @param string $name The annotation name
|
* @param string $name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of annotations
|
* @return array An array of tags
|
||||||
*/
|
*/
|
||||||
public function findAnnotatedServiceIds($name)
|
public function findTaggedServiceIds($name)
|
||||||
{
|
{
|
||||||
static $annotations = array (
|
static $tags = array (
|
||||||
);
|
);
|
||||||
|
|
||||||
return isset($annotations[$name]) ? $annotations[$name] : array();
|
return isset($tags[$name]) ? $tags[$name] : array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,18 +25,18 @@ class ProjectServiceContainer extends Container
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns service ids for a given annotation.
|
* Returns service ids for a given tag.
|
||||||
*
|
*
|
||||||
* @param string $name The annotation name
|
* @param string $name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of annotations
|
* @return array An array of tags
|
||||||
*/
|
*/
|
||||||
public function findAnnotatedServiceIds($name)
|
public function findTaggedServiceIds($name)
|
||||||
{
|
{
|
||||||
static $annotations = array (
|
static $tags = array (
|
||||||
);
|
);
|
||||||
|
|
||||||
return isset($annotations[$name]) ? $annotations[$name] : array();
|
return isset($tags[$name]) ? $tags[$name] : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,15 +153,15 @@ class ProjectServiceContainer extends Container
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns service ids for a given annotation.
|
* Returns service ids for a given tag.
|
||||||
*
|
*
|
||||||
* @param string $name The annotation name
|
* @param string $name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of annotations
|
* @return array An array of tags
|
||||||
*/
|
*/
|
||||||
public function findAnnotatedServiceIds($name)
|
public function findTaggedServiceIds($name)
|
||||||
{
|
{
|
||||||
static $annotations = array (
|
static $tags = array (
|
||||||
'foo' =>
|
'foo' =>
|
||||||
array (
|
array (
|
||||||
'foo' =>
|
'foo' =>
|
||||||
@ -178,7 +178,7 @@ class ProjectServiceContainer extends Container
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return isset($annotations[$name]) ? $annotations[$name] : array();
|
return isset($tags[$name]) ? $tags[$name] : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
</parameters>
|
</parameters>
|
||||||
<services>
|
<services>
|
||||||
<service id="foo" class="FooClass" factory-method="getInstance" shared="false">
|
<service id="foo" class="FooClass" factory-method="getInstance" shared="false">
|
||||||
<annotation name="foo" foo="foo" />
|
<tag name="foo" foo="foo" />
|
||||||
<annotation name="foo" bar="bar" />
|
<tag name="foo" bar="bar" />
|
||||||
<file>%path%foo.php</file>
|
<file>%path%foo.php</file>
|
||||||
<argument>foo</argument>
|
<argument>foo</argument>
|
||||||
<argument type="service" id="foo.baz" />
|
<argument type="service" id="foo.baz" />
|
||||||
|
@ -6,7 +6,7 @@ parameters:
|
|||||||
services:
|
services:
|
||||||
foo:
|
foo:
|
||||||
class: FooClass
|
class: FooClass
|
||||||
annotations:
|
tags:
|
||||||
- { name: foo, foo: foo }
|
- { name: foo, foo: foo }
|
||||||
- { name: foo, bar: bar }
|
- { name: foo, bar: bar }
|
||||||
file: %path%foo.php
|
file: %path%foo.php
|
||||||
|
Reference in New Issue
Block a user