/** * Gets multiple photos * * @param array $ids List of photo ids * @param array $options * @see SimplePhoto::build() * @return mixed|PhotoCollection */ public function collection(array $ids, array $options = array()) { $photos = $this->dataStore->getPhotos($ids); if (empty($photos) && !$this->storageManager->hasFallback()) { // If no fallback has been defined, and no photo was found // lets just skip the computation that follows. return $this->createPhotoCollection(); } $found = array(); array_map(function ($photo) use($ids, &$found) { // This will be used to build found Photos return $found[$photo['id']] = $photo; }, $photos); $sorted = array(); foreach ($ids as $index => $id) { $photo = array(); if (array_key_exists($id, $found)) { $photo = $found[$id]; } $sorted[$index] = $photo; } $photos = $this->createPhotoCollection($sorted); $simplePhoto = $this; // php 5.3 compatibility $photos->transform(function ($photo) use($simplePhoto, $options) { return $simplePhoto->build($photo, $options); })->ksort(); return $photos; }
public function testFallback() { $this->storageManager->setFallback(new MemoryStorage()); $this->assertTrue($this->storageManager->hasFallback()); }