Author: fabien
Date: 2010-02-09 18:00:14 +0100 (Tue, 09 Feb 2010)
New Revision: 27789

Added:
   
branches/2.0/src/Symfony/Components/DependencyInjection/AnnotatedContainerInterface.php
Modified:
   branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
   branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
   branches/2.0/src/Symfony/Components/DependencyInjection/Definition.php
   
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/GraphvizDumper.php
   branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php
   branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/XmlDumper.php
   branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/YamlDumper.php
   
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php
   
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/YamlFileLoader.php
   
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
   
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/containers/container9.php
   
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services1-1.php
   
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services1.php
   
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services8.php
   
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
   
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services9.xml
   
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services9.yml
   
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderTest.php
   
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php
   
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/DefinitionTest.php
Log:
Merge branch 'master' of git://github.com/symfony/symfony

Added: 
branches/2.0/src/Symfony/Components/DependencyInjection/AnnotatedContainerInterface.php
===================================================================
--- 
branches/2.0/src/Symfony/Components/DependencyInjection/AnnotatedContainerInterface.php
                             (rev 0)
+++ 
branches/2.0/src/Symfony/Components/DependencyInjection/AnnotatedContainerInterface.php
     2010-02-09 17:00:14 UTC (rev 27789)
@@ -0,0 +1,31 @@
+<?php
+
+namespace Symfony\Components\DependencyInjection;
+
+/*
+ * This file is part of the symfony framework.
+ *
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * AnnotatedContainerInterface is the interface implemented when a container 
knows how to deals with annotations.
+ *
+ * @package    symfony
+ * @subpackage dependency_injection
+ * @author     Fabien Potencier <[email protected]>
+ */
+interface AnnotatedContainerInterface
+{
+  /**
+   * Returns service ids for a given annotation.
+   *
+   * @param string $name The annotation name
+   *
+   * @return array An array of annotations
+   */
+  public function findAnnotatedServiceIds($name);
+}

Modified: branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php
===================================================================
--- branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php 
2010-02-09 16:11:02 UTC (rev 27788)
+++ branches/2.0/src/Symfony/Components/DependencyInjection/Builder.php 
2010-02-09 17:00:14 UTC (rev 27789)
@@ -18,7 +18,7 @@
  * @subpackage dependency_injection
  * @author     Fabien Potencier <[email protected]>
  */
-class Builder extends Container
+class Builder extends Container implements AnnotatedContainerInterface
 {
   protected $definitions = array();
   protected $aliases     = array();
@@ -481,6 +481,27 @@
     return $value;
   }
 
+  /**
+   * Returns service ids for a given annotation.
+   *
+   * @param string $name The annotation name
+   *
+   * @return array An array of annotations
+   */
+  public function findAnnotatedServiceIds($name)
+  {
+    $annotations = array();
+    foreach ($this->getDefinitions() as $id => $definition)
+    {
+      if ($definition->getAnnotation($name))
+      {
+        $annotations[$id] = $definition->getAnnotation($name);
+      }
+    }
+
+    return $annotations;
+  }
+
   static public function getServiceConditionals($value)
   {
     $services = array();

Modified: branches/2.0/src/Symfony/Components/DependencyInjection/Container.php
===================================================================
--- branches/2.0/src/Symfony/Components/DependencyInjection/Container.php       
2010-02-09 16:11:02 UTC (rev 27788)
+++ branches/2.0/src/Symfony/Components/DependencyInjection/Container.php       
2010-02-09 17:00:14 UTC (rev 27789)
@@ -50,12 +50,10 @@
  * @subpackage dependency_injection
  * @author     Fabien Potencier <[email protected]>
  */
-class Container implements ContainerInterface, \ArrayAccess, \Iterator
+class Container implements ContainerInterface, \ArrayAccess
 {
-  protected $serviceIds = array();
   protected $parameters = array();
   protected $services   = array();
-  protected $count      = 0;
 
   const EXCEPTION_ON_INVALID_REFERENCE = 1;
   const NULL_ON_INVALID_REFERENCE      = 2;
@@ -326,56 +324,6 @@
   }
 
   /**
-   * Resets the service identifiers array to the beginning (implements the 
Iterator interface).
-   */
-  public function rewind()
-  {
-    $this->serviceIds = $this->getServiceIds();
-
-    $this->count = count($this->serviceIds);
-  }
-
-  /**
-   * Gets the key associated with the current service (implements the Iterator 
interface).
-   *
-   * @return string The service identifier
-   */
-  public function key()
-  {
-    return current($this->serviceIds);
-  }
-
-  /**
-   * Returns the current service (implements the Iterator interface).
-   *
-   * @return mixed The service
-   */
-  public function current()
-  {
-    return $this->getService(current($this->serviceIds));
-  }
-
-  /**
-   * Moves to the next service (implements the Iterator interface).
-   */
-  public function next()
-  {
-    next($this->serviceIds);
-
-    --$this->count;
-  }
-
-  /**
-   * Returns true if the current service is valid (implements the Iterator 
interface).
-   *
-   * @return boolean The validity of the current service; true if it is valid
-   */
-  public function valid()
-  {
-    return $this->count > 0;
-  }
-
-  /**
    * Catches unknown methods.
    *
    * @param string $method    The called method name

Modified: branches/2.0/src/Symfony/Components/DependencyInjection/Definition.php
===================================================================
--- branches/2.0/src/Symfony/Components/DependencyInjection/Definition.php      
2010-02-09 16:11:02 UTC (rev 27788)
+++ branches/2.0/src/Symfony/Components/DependencyInjection/Definition.php      
2010-02-09 17:00:14 UTC (rev 27789)
@@ -27,6 +27,7 @@
   protected $arguments;
   protected $calls;
   protected $configurator;
+  protected $annotations;
 
   /**
    * Constructor.
@@ -40,6 +41,7 @@
     $this->arguments = $arguments;
     $this->calls = array();
     $this->shared = true;
+    $this->annotations = array();
   }
 
   /**
@@ -172,6 +174,53 @@
   }
 
   /**
+   * Returns all annotations.
+   *
+   * @return array An array of annotations
+   */
+  public function getAnnotations()
+  {
+    return $this->annotations;
+  }
+
+  /**
+   * Gets an annotation by name.
+   *
+   * @param  string $name       The annotation name
+   *
+   * @return array  $attributes An array of attributes
+   */
+  public function getAnnotation($name)
+  {
+    if (!isset($this->annotations[$name]))
+    {
+      $this->annotations[$name] = array();
+    }
+
+    return $this->annotations[$name];
+  }
+
+  /**
+   * Adds an annotation for this definition.
+   *
+   * @param  string $name       The annotation name
+   * @param  array  $attributes An array of attributes
+   *
+   * @return Definition The current instance
+   */
+  public function addAnnotation($name, array $attributes = array())
+  {
+    if (!isset($this->annotations[$name]))
+    {
+      $this->annotations[$name] = array();
+    }
+
+    $this->annotations[$name][] = $attributes;
+
+    return $this;
+  }
+
+  /**
    * Sets a file to require before creating the service.
    *
    * @param  string $file A full pathname to include

Modified: 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/GraphvizDumper.php
===================================================================
--- 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/GraphvizDumper.php
   2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/GraphvizDumper.php
   2010-02-09 17:00:14 UTC (rev 27789)
@@ -158,8 +158,10 @@
       $container->setDefinition($id, new Definition('stdClass'));
     }
 
-    foreach ($container as $id => $service)
+    foreach ($container->getServiceIds() as $id)
     {
+      $service = $container->getService($id);
+
       if (in_array($id, array_keys($container->getAliases())))
       {
         continue;

Modified: 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php
===================================================================
--- 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php    
    2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php    
    2010-02-09 17:00:14 UTC (rev 27789)
@@ -48,6 +48,7 @@
       $this->startClass($options['class'], $options['base_class']).
       $this->addConstructor().
       $this->addServices().
+      $this->addAnnotations().
       $this->addDefaultParametersMethod().
       $this->endClass()
     ;
@@ -111,7 +112,7 @@
     }
     else
     {
-      if ($class != "'".$definition->getClass()."'")
+      if ($class != "'".str_replace('\\', '\\\\', $definition->getClass())."'")
       {
         return sprintf("    \$class = %s;\n    \$instance = new 
\$class(%s);\n", $class, implode(', ', $arguments));
       }
@@ -246,6 +247,42 @@
     return $code;
   }
 
+  protected function addAnnotations()
+  {
+    $annotations = array();
+    foreach ($this->container->getDefinitions() as $id => $definition)
+    {
+      foreach ($definition->getAnnotations() as $name => $ann)
+      {
+        if (!isset($annotations[$name]))
+        {
+          $annotations[$name] = array();
+        }
+
+        $annotations[$name][$id] = $ann;
+      }
+    }
+    $annotations = var_export($annotations, true);
+
+    return <<<EOF
+
+  /**
+   * Returns service ids for a given annotation.
+   *
+   * @param string \$name The annotation name
+   *
+   * @return array An array of annotations
+   */
+  public function findAnnotatedServiceIds(\$name)
+  {
+    static \$annotations = $annotations;
+
+    return isset(\$annotations[\$name]) ? \$annotations[\$name] : array();
+  }
+
+EOF;
+  }
+
   protected function startClass($class, $baseClass)
   {
     $properties = array();

Modified: 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/XmlDumper.php
===================================================================
--- 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/XmlDumper.php    
    2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/XmlDumper.php    
    2010-02-09 17:00:14 UTC (rev 27789)
@@ -55,6 +55,21 @@
       !$definition->isShared() ? ' shared="false"' : ''
     );
 
+    foreach ($definition->getAnnotations() as $name => $annotations)
+    {
+      foreach ($annotations as $attributes)
+      {
+        $att = array();
+        foreach ($attributes as $key => $value)
+        {
+          $att[] = sprintf('%s="%s"', $key, $value);
+        }
+        $att = $att ? ' '.implode(' ', $att) : '';
+
+        $code .= sprintf("      <annotation name=\"%s\"%s />\n", $name, $att);
+      }
+    }
+
     if ($definition->getFile())
     {
       $code .= sprintf("      <file>%s</file>\n", $definition->getFile());

Modified: 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/YamlDumper.php
===================================================================
--- 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/YamlDumper.php   
    2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/src/Symfony/Components/DependencyInjection/Dumper/YamlDumper.php   
    2010-02-09 17:00:14 UTC (rev 27789)
@@ -42,6 +42,26 @@
     $code = "  $id:\n";
     $code .= sprintf("    class: %s\n", $definition->getClass());
 
+    $annotationsCode = '';
+    foreach ($definition->getAnnotations() as $name => $annotations)
+    {
+      foreach ($annotations as $attributes)
+      {
+        $att = array();
+        foreach ($attributes as $key => $value)
+        {
+          $att[] = sprintf('%s: %s', YAML::dump($key), YAML::dump($value));
+        }
+        $att = $att ? ', '.implode(' ', $att) : '';
+
+        $annotationsCode .= sprintf("      - { name: %s%s }\n", 
YAML::dump($name), $att);
+      }
+    }
+    if ($annotationsCode)
+    {
+      $code .= "    annotations:\n".$annotationsCode;
+    }
+
     if ($definition->getFile())
     {
       $code .= sprintf("    file: %s\n", $definition->getFile());

Modified: 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php
===================================================================
--- 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php
    2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/XmlFileLoader.php
    2010-02-09 17:00:14 UTC (rev 27789)
@@ -178,6 +178,22 @@
       $definition->addMethodCall((string) $call['method'], 
$call->getArgumentsAsPhp('argument'));
     }
 
+    foreach ($service->annotation as $annotation)
+    {
+      $parameters = array();
+      foreach ($annotation->attributes() as $name => $value)
+      {
+        if ('name' === $name)
+        {
+          continue;
+        }
+
+        $parameters[$name] = SimpleXMLElement::phpize($value);
+      }
+
+      $definition->addAnnotation((string) $annotation['name'], $parameters);
+    }
+
     $configuration->setDefinition($id, $definition);
   }
 

Modified: 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/YamlFileLoader.php
===================================================================
--- 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/YamlFileLoader.php
   2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/YamlFileLoader.php
   2010-02-09 17:00:14 UTC (rev 27789)
@@ -177,6 +177,17 @@
       }
     }
 
+    if (isset($service['annotations']))
+    {
+      foreach ($service['annotations'] as $annotation)
+      {
+        $name = $annotation['name'];
+        unset($annotation['name']);
+
+        $definition->addAnnotation($name, $annotation);
+      }
+    }
+
     $configuration->setDefinition($id, $definition);
   }
 

Modified: 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
===================================================================
--- 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
 2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/src/Symfony/Components/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
 2010-02-09 17:00:14 UTC (rev 27789)
@@ -84,6 +84,7 @@
       <xsd:element name="argument" type="argument" minOccurs="0" 
maxOccurs="unbounded" />
       <xsd:element name="configurator" type="configurator" minOccurs="0" 
maxOccurs="1" />
       <xsd:element name="call" type="call" minOccurs="0" maxOccurs="unbounded" 
/>
+      <xsd:element name="annotation" type="annotation" minOccurs="0" 
maxOccurs="unbounded" />
     </xsd:choice>
     <xsd:attribute name="id" type="xsd:string" />
     <xsd:attribute name="class" type="xsd:string" />
@@ -92,6 +93,11 @@
     <xsd:attribute name="alias" type="xsd:string" />
   </xsd:complexType>
 
+  <xsd:complexType name="annotation">
+    <xsd:attribute name="name" type="xsd:string" />
+    <xsd:anyAttribute namespace="##any" processContents="lax" />
+  </xsd:complexType>
+
   <xsd:complexType name="parameters">
     <xsd:sequence>
       <xsd:element name="parameter" type="parameter" minOccurs="1" 
maxOccurs="unbounded" />

Modified: 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/containers/container9.php
===================================================================
--- 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/containers/container9.php
        2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/containers/container9.php
        2010-02-09 17:00:14 UTC (rev 27789)
@@ -10,6 +10,8 @@
 $container = new Builder();
 $container->
   register('foo', 'FooClass')->
+  addAnnotation('foo', array('foo' => 'foo'))->
+  addAnnotation('foo', array('bar' => 'bar'))->
   setConstructor('getInstance')->
   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'))->

Modified: 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services1-1.php
===================================================================
--- 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services1-1.php
      2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services1-1.php
      2010-02-09 17:00:14 UTC (rev 27789)
@@ -13,4 +13,19 @@
 class Container extends AbstractContainer
 {
   protected $shared = array();
+
+  /**
+   * Returns service ids for a given annotation.
+   *
+   * @param string $name The annotation name
+   *
+   * @return array An array of annotations
+   */
+  public function findAnnotatedServiceIds($name)
+  {
+    static $annotations = array (
+);
+
+    return isset($annotations[$name]) ? $annotations[$name] : array();
+  }
 }

Modified: 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services1.php
===================================================================
--- 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services1.php
        2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services1.php
        2010-02-09 17:00:14 UTC (rev 27789)
@@ -13,4 +13,19 @@
 class ProjectServiceContainer extends Container
 {
   protected $shared = array();
+
+  /**
+   * Returns service ids for a given annotation.
+   *
+   * @param string $name The annotation name
+   *
+   * @return array An array of annotations
+   */
+  public function findAnnotatedServiceIds($name)
+  {
+    static $annotations = array (
+);
+
+    return isset($annotations[$name]) ? $annotations[$name] : array();
+  }
 }

Modified: 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services8.php
===================================================================
--- 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services8.php
        2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services8.php
        2010-02-09 17:00:14 UTC (rev 27789)
@@ -19,10 +19,27 @@
    */
   public function __construct()
   {
-    parent::__construct($this->getDefaultParameters());
+    parent::__construct();
+
+    $this->parameters = $this->getDefaultParameters();
   }
 
   /**
+   * Returns service ids for a given annotation.
+   *
+   * @param string $name The annotation name
+   *
+   * @return array An array of annotations
+   */
+  public function findAnnotatedServiceIds($name)
+  {
+    static $annotations = array (
+);
+
+    return isset($annotations[$name]) ? $annotations[$name] : array();
+  }
+
+  /**
    * Gets the default parameters.
    *
    * @return array An array of the default parameters

Modified: 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
===================================================================
--- 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
        2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/php/services9.php
        2010-02-09 17:00:14 UTC (rev 27789)
@@ -26,7 +26,9 @@
    */
   public function __construct()
   {
-    parent::__construct($this->getDefaultParameters());
+    parent::__construct();
+
+    $this->parameters = $this->getDefaultParameters();
   }
 
   /**
@@ -138,6 +140,35 @@
   }
 
   /**
+   * Returns service ids for a given annotation.
+   *
+   * @param string $name The annotation name
+   *
+   * @return array An array of annotations
+   */
+  public function findAnnotatedServiceIds($name)
+  {
+    static $annotations = array (
+  'foo' => 
+  array (
+    'foo' => 
+    array (
+      0 => 
+      array (
+        'foo' => 'foo',
+      ),
+      1 => 
+      array (
+        'bar' => 'bar',
+      ),
+    ),
+  ),
+);
+
+    return isset($annotations[$name]) ? $annotations[$name] : array();
+  }
+
+  /**
    * Gets the default parameters.
    *
    * @return array An array of the default parameters

Modified: 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services9.xml
===================================================================
--- 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services9.xml
        2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/xml/services9.xml
        2010-02-09 17:00:14 UTC (rev 27789)
@@ -10,6 +10,8 @@
   </parameters>
   <services>
     <service id="foo" class="FooClass" constructor="getInstance" 
shared="false">
+      <annotation name="foo" foo="foo" />
+      <annotation name="foo" bar="bar" />
       <file>%path%/foo.php</file>
       <argument>foo</argument>
       <argument type="service" id="foo.baz" />

Modified: 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services9.yml
===================================================================
--- 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services9.yml
       2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/fixtures/Symfony/Components/DependencyInjection/yaml/services9.yml
       2010-02-09 17:00:14 UTC (rev 27789)
@@ -6,6 +6,9 @@
 services:
   foo:
     class: FooClass
+    annotations:
+      - { name: foo, foo: foo }
+      - { name: foo, bar: bar }
     file: %path%/foo.php
     constructor: getInstance
     arguments: [foo, '@foo.baz', { '%foo%': 'foo is %foo%', bar: '%foo%' }, 
true, '@service_container']

Modified: 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderTest.php
===================================================================
--- 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderTest.php  
    2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/BuilderTest.php  
    2010-02-09 17:00:14 UTC (rev 27789)
@@ -17,7 +17,7 @@
 
 $fixturesPath = 
__DIR__.'/../../../../fixtures/Symfony/Components/DependencyInjection/';
 
-$t = new LimeTest(59);
+$t = new LimeTest(61);
 
 // ->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() 
->getDefinition() ->hasDefinition()
 $t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions() 
->setDefinition() ->getDefinition() ->hasDefinition()');
@@ -290,3 +290,20 @@
 $config->setDefinition('foo', new Definition('BazClass'));
 $container->merge($config);
 $t->is($container->getDefinition('foo')->getClass(), 'BazClass', '->merge() 
overrides already defined services');
+
+// ->findAnnotatedServiceIds()
+$t->diag('->findAnnotatedServiceIds()');
+$builder = new Builder();
+$builder
+  ->register('foo', 'FooClass')
+  ->addAnnotation('foo', array('foo' => 'foo'))
+  ->addAnnotation('bar', array('bar' => 'bar'))
+  ->addAnnotation('foo', array('foofoo' => 'foofoo'))
+;
+$t->is($builder->findAnnotatedServiceIds('foo'), array(
+  'foo' => array(
+    array('foo' => 'foo'),
+    array('foofoo' => 'foofoo'),
+  )
+), '->findAnnotatedServiceIds() returns an array of service ids and its 
annotation attributes');
+$t->is($builder->findAnnotatedServiceIds('foobar'), array(), 
'->findAnnotatedServiceIds() returns an empty array if there is annotated 
services');

Modified: 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php
===================================================================
--- 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php
    2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/ContainerTest.php
    2010-02-09 17:00:14 UTC (rev 27789)
@@ -14,7 +14,7 @@
 
 $fixturesPath = 
__DIR__.'/../../../../fixtures/Symfony/Components/DependencyInjection/';
 
-$t = new LimeTest(43);
+$t = new LimeTest(42);
 
 // __construct()
 $t->diag('__construct()');
@@ -190,23 +190,6 @@
 $t->is(spl_object_hash($sc->getService('foo_bar')), 
spl_object_hash($sc->__foo_bar), '->getService() camelizes the service id when 
looking for a method');
 $t->is(spl_object_hash($sc->getService('foo.baz')), 
spl_object_hash($sc->__foo_baz), '->getService() camelizes the service id when 
looking for a method');
 
-// Iterator
-$t->diag('implements Iterator');
-$sc = new ProjectServiceContainer();
-$sc->setService('foo', $foo = new stdClass());
-$services = array();
-foreach ($sc as $id => $service)
-{
-  $services[$id] = spl_object_hash($service);
-}
-$t->is($services, array(
-  'service_container' => spl_object_hash($sc),
-  'bar' => spl_object_hash($sc->__bar),
-  'foo_bar' => spl_object_hash($sc->__foo_bar),
-  'foo.baz' => spl_object_hash($sc->__foo_baz),
-  'foo' => spl_object_hash($foo)),
-'Container implements the Iterator interface');
-
 // __call()
 $t->diag('__call()');
 $sc = new Container();

Modified: 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/DefinitionTest.php
===================================================================
--- 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/DefinitionTest.php
   2010-02-09 16:11:02 UTC (rev 27788)
+++ 
branches/2.0/tests/unit/Symfony/Components/DependencyInjection/DefinitionTest.php
   2010-02-09 17:00:14 UTC (rev 27789)
@@ -12,7 +12,7 @@
 
 use Symfony\Components\DependencyInjection\Definition;
 
-$t = new LimeTest(21);
+$t = new LimeTest(25);
 
 // __construct()
 $t->diag('__construct()');
@@ -69,3 +69,16 @@
 $def = new Definition('stdClass');
 $t->is(spl_object_hash($def->setConfigurator('foo')), spl_object_hash($def), 
'->setConfigurator() implements a fluent interface');
 $t->is($def->getConfigurator(), 'foo', '->getConfigurator() returns the 
configurator');
+
+// ->getAnnotations() ->getAnnotation() ->addAnnotation()
+$t->diag('->getAnnotations() ->getAnnotation() ->addAnnotation()');
+$def = new Definition('stdClass');
+$t->is(spl_object_hash($def->addAnnotation('foo')), spl_object_hash($def), 
'->addAnnotation() implements a fluent interface');
+$t->is($def->getAnnotation('foo'), array(array()), '->getAnnotation() returns 
attributes for an annotation name');
+$def->addAnnotation('foo', array('foo' => 'bar'));
+$t->is($def->getAnnotation('foo'), array(array(), array('foo' => 'bar')), 
'->addAnnotation() can adds the same annotation several times');
+$def->addAnnotation('bar', array('bar' => 'bar'));
+$t->is($def->getAnnotations(), array(
+  'foo' => array(array(), array('foo' => 'bar')),
+  'bar' => array(array('bar' => 'bar')),
+), '->getAnnotations() returns all annotations');

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to