Imbo\Resource\GlobalShortUrl::getImage PHP Method

getImage() public method

Fetch an image via a short URL
public getImage ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface
    public function getImage(EventInterface $event)
    {
        $request = $event->getRequest();
        $route = $request->getRoute();
        $params = $event->getDatabase()->getShortUrlParams($route->get('shortUrlId'));
        if (!$params) {
            throw new ResourceException('Image not found', 404);
        }
        $route->set('user', $params['user']);
        $route->set('imageIdentifier', $params['imageIdentifier']);
        $route->set('extension', $params['extension']);
        $request->query = new ParameterBag($params['query']);
        $event->getResponse()->headers->set('X-Imbo-ShortUrl', $request->getUri());
        $event->getManager()->trigger('image.get', ['skipAccessControl' => true]);
    }

Usage Example

Beispiel #1
0
 /**
  * @covers Imbo\Resource\GlobalShortUrl::getImage
  * @expectedException Imbo\Exception\ResourceException
  * @expectedExceptionMessage Image not found
  * @expectedExceptionCode 404
  */
 public function testRespondsWith404WhenShortUrlDoesNotExist()
 {
     $route = $this->getMock('Imbo\\Router\\Route');
     $route->expects($this->once())->method('get')->with('shortUrlId')->will($this->returnValue('aaaaaaa'));
     $this->request->expects($this->once())->method('getRoute')->will($this->returnValue($route));
     $this->database->expects($this->once())->method('getShortUrlParams')->with('aaaaaaa')->will($this->returnValue(null));
     $this->resource->getImage($this->event);
 }