Пример #1
0
 /**
  * @param ResourceMap $map
  */
 public function modify(ResourceMap $map)
 {
     $newMap = $map->getMap();
     // Collection of maps that does not exist in the new map.
     $notCloned = $this->map;
     foreach ($map->getMap() as $newResource => $oldResource) {
         foreach ($this->map as $originalNewResource => $initialResource) {
             $position = array_search($originalNewResource, $newMap[$newResource]);
             if ($position !== false) {
                 array_splice($newMap[$newResource], $position, 1, $initialResource);
                 unset($notCloned[$originalNewResource]);
             }
         }
     }
     $this->map = array_merge($newMap, $notCloned);
 }
Пример #2
0
 public function test_combine_Sanity()
 {
     $original = new ResourceMap();
     $original->map(['a1', 'a2'], 'b');
     $original->map('d', 'n');
     $original->map('only', 'old');
     $modified = new ResourceMap();
     $modified->map(['b0', 'b', 'b2'], 'c');
     $modified->map('only', 'new');
     $modified->map(['b', 'n'], 'm');
     $original->modify($modified);
     $this->assertEquals(['c' => ['b0', 'a1', 'a2', 'b2'], 'new' => ['only'], 'old' => ['only'], 'm' => ['a1', 'a2', 'd']], $original->getMap());
 }