/**
  * {@inheritdoc}
  */
 public function createCollection(array $data = [])
 {
     $collection = new GenericCollection();
     foreach ($data as $item) {
         $collection->add(null, $this->create($item));
     }
     return $collection;
 }
 /**
  * {@inheritdoc}
  */
 public function createCollection(array $data = [])
 {
     $collection = new GenericCollection();
     if (array_key_exists('networks', $data)) {
         $data = $data['networks'];
     }
     foreach ($data as $item) {
         $collection->add(null, $this->create($item));
     }
     return $collection;
 }
Esempio n. 3
0
 /**
  * @param  array             $data
  * @param $class
  * @return GenericCollection
  */
 public function createCollection(array $data, $class)
 {
     if (is_object($class)) {
         $class = get_class($class);
     }
     $collection = new GenericCollection();
     $objectHydrator = new ObjectHydrator();
     foreach ($data as $item) {
         $collection->add(null, $objectHydrator->hydrate(new $class(), $item));
     }
     return $collection;
 }
Esempio n. 4
0
 /**
  * Create a generic collection of data and map it on the class by it's static parameter $properties
  *
  * @param  array             $data
  * @param $class
  * @return GenericCollection
  */
 protected function createGenericCollection($data = array(), $class)
 {
     if (is_object($class)) {
         $class = get_class($class);
     }
     $collection = new GenericCollection();
     if (null === $data) {
         return $collection;
     }
     foreach ($data as $item) {
         $collection->add(null, $this->hydrate(new $class(), $item));
     }
     return $collection;
 }
 /**
  * @test
  */
 public function shouldBeAbleToSetAndGet()
 {
     $this->setUp();
     $this->collection->set('id', 2);
     $this->assertEquals(2, $this->collection['id']);
     $object = new \stdClass();
     $object->id = 1;
     $hash = spl_object_hash($object);
     $this->collection->set(null, $object);
     $this->assertEquals($object, $this->collection->get($hash));
     $this->assertEquals(3, count($this->collection));
     $retrievedObject = $this->collection->get($object);
     $this->assertEquals($object, $retrievedObject);
     $this->collection->remove($object);
     $this->assertEquals(2, count($this->collection));
     $keys = $this->collection->getKeys();
     $this->assertEquals(['id', 'name'], $keys);
     $this->assertEquals(true, $this->collection->hasKey('id'));
     $this->assertEquals('id', $this->collection->keySearch('id'));
     $this->assertEquals(false, $this->collection->keySearch('parent'));
     $this->collection->replace(['id' => 2]);
     $this->assertEquals(1, count($this->collection));
     $this->assertEquals(2, $this->collection->get('id'));
     $this->collection->merge(['id' => 1]);
     $this->assertEquals([2, 1], $this->collection->get('id'));
     $this->setUp();
     $this->assertEquals(['id' => 1, 'name' => 'Dave'], $this->collection->getAll());
     $this->assertEquals(['name' => 'Dave'], $this->collection->getAll(['name']));
     $this->collection->clear();
     $this->assertEquals(0, count($this->collection));
 }
 /**
  * {@inheritdoc}
  */
 public function createCollection(array $data = [])
 {
     if (array_key_exists('certifications', $data)) {
         $data = $data['certifications'];
     }
     $collection = new GenericCollection();
     foreach ($data as $country => $certifications) {
         $certification = new Certification();
         $certification->setCountry($country);
         foreach ($certifications as $countryCertification) {
             $object = $this->create($countryCertification);
             $certification->getCertifications()->add(null, $object);
         }
         $collection->add(null, $certification);
     }
     return $collection;
 }
 /**
  * {@inheritdoc}
  */
 public function createCollection(array $data = [])
 {
     $collection = new GenericCollection();
     $collection->add(null, $this->create($data));
     return $collection;
 }
 /**
  * Create an generic collection of an array that consists out of a mix of movies and tv shows
  *
  * @param  array             $data
  * @return GenericCollection
  */
 protected function createGenericCollectionFromMediaTypes($data = [])
 {
     $movieFactory = new MovieFactory($this->getHttpClient());
     $tvFactory = new TvFactory($this->getHttpClient());
     $collection = new GenericCollection();
     foreach ($data as $item) {
         switch ($item['media_type']) {
             case "movie":
                 $collection->add(null, $movieFactory->create($item));
                 break;
             case "tv":
                 $collection->add(null, $tvFactory->create($item));
                 break;
             default:
                 throw new \RuntimeException('Unknown media type "%s"', $item['media_type']);
         }
     }
     return $collection;
 }