/**
  * Maps resources request to a ResourceCollection
  *
  * @return ResourceCollection
  */
 public function map($context, array $resources)
 {
     $collection = new ResourceCollection($context);
     foreach ($resources as $location => $resource) {
         if (is_int($location)) {
             $collection->add(new Resource($resource, $this->locator->locate($context, $resource)));
         } else {
             $collection->add(new Resource($resource, ltrim($location, '/')));
         }
     }
     return $collection;
 }
Exemplo n.º 2
0
 public function test_apply_ManyMaps()
 {
     $map = new ResourceMap();
     $map->map(['b', 'c'], 'new');
     $map->map('a', 'n');
     $collection = new ResourceCollection();
     $collection->add('1')->add('b')->add('c')->add('a');
     $map->apply($collection);
     $this->assertEquals(['1', 'new', 'n'], $collection->get());
 }
Exemplo n.º 3
0
 public function test_iteration()
 {
     $expected = ['a', 'b', 'c'];
     $curr = 0;
     $collection = new ResourceCollection();
     $collection->add('a');
     $collection->add('b');
     $collection->add('c');
     foreach ($collection as $value) {
         $this->assertEquals($expected[$curr++], $value);
     }
     $this->assertEquals(count($expected), $curr);
 }