Imbo\EventListener\StorageOperations::loadImage PHP Method

loadImage() public method

Load an image
public loadImage ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface An event instance
    public function loadImage(EventInterface $event)
    {
        $storage = $event->getStorage();
        $request = $event->getRequest();
        $response = $event->getResponse();
        $user = $request->getUser();
        $imageIdentifier = $request->getImageIdentifier();
        $imageData = $storage->getImage($user, $imageIdentifier);
        $lastModified = $storage->getLastModified($user, $imageIdentifier);
        $response->setLastModified($lastModified)->getModel()->setBlob($imageData);
        $event->getManager()->trigger('image.loaded');
    }

Usage Example

 /**
  * @covers Imbo\EventListener\StorageOperations::loadImage
  */
 public function testCanLoadImage()
 {
     $date = new DateTime();
     $this->storage->expects($this->once())->method('getImage')->with($this->publicKey, $this->imageIdentifier)->will($this->returnValue('image data'));
     $this->storage->expects($this->once())->method('getLastModified')->with($this->publicKey, $this->imageIdentifier)->will($this->returnValue($date));
     $this->response->expects($this->once())->method('setLastModified')->with($date)->will($this->returnSelf());
     $image = $this->getMock('Imbo\\Model\\Image');
     $image->expects($this->once())->method('setBlob')->with('image data');
     $this->response->expects($this->once())->method('getModel')->will($this->returnValue($image));
     $eventManager = $this->getMock('Imbo\\EventManager\\EventManager');
     $eventManager->expects($this->once())->method('trigger')->with('image.loaded');
     $this->event->expects($this->once())->method('getManager')->will($this->returnValue($eventManager));
     $this->listener->loadImage($this->event);
 }