예제 #1
0
 /**
  * @test
  */
 public function mergeBags()
 {
     $bags = array();
     $expected = array();
     for ($i = 0; $i < 10; $i++) {
         $bag = new AttributeBag();
         $attributes = array('someName' . $i => $i, 'anotherSomeName' . $i => $i);
         foreach ($attributes as $name => $value) {
             $bag->add($name, $value);
         }
         $bags[] = $bag;
         $expected = array_merge($attributes, $expected);
     }
     $bag = AttributeBag::merge($bags);
     $this->assertEquals($expected, $bag->getAll());
 }
예제 #2
0
 /**
  * Marge couple of BagContainers into one object. 
  * 
  * Result of merging always is BagContainer.
  *
  * @param array $containers
  * @return BagContainer Result of merging
  */
 public static function merge(array $containers)
 {
     $attributeBags = array();
     $weight = 0;
     foreach ($containers as $container) {
         $weight = max($weight, $container->getWeight());
         $attributeBags[] = $container->getAttributeBag();
     }
     $container = new static();
     $container->attributeBag = AttributeBag::merge($attributeBags);
     $container->weight = $weight;
     return $container;
 }