Imbo\Resource\Index::get PHP Method

get() public method

Handle GET requests
public get ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The current event
    public function get(EventInterface $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();
        $response->setStatusCode(200, 'Hell Yeah');
        $baseUrl = $request->getSchemeAndHttpHost() . $request->getBaseUrl();
        $model = new Model\ArrayModel();
        $model->setData(['version' => Version::VERSION, 'urls' => ['site' => 'http://www.imbo-project.org', 'source' => 'https://github.com/imbo/imbo', 'issues' => 'https://github.com/imbo/imbo/issues', 'docs' => 'http://docs.imbo-project.org'], 'endpoints' => ['status' => $baseUrl . '/status', 'stats' => $baseUrl . '/stats', 'user' => $baseUrl . '/users/{user}', 'images' => $baseUrl . '/users/{user}/images', 'image' => $baseUrl . '/users/{user}/images/{imageIdentifier}', 'globalShortImageUrl' => $baseUrl . '/s/{id}', 'globalImages' => $baseUrl . '/images', 'metadata' => $baseUrl . '/users/{user}/images/{imageIdentifier}/metadata', 'shortImageUrls' => $baseUrl . '/users/{user}/images/{imageIdentifier}/shorturls', 'shortImageUrl' => $baseUrl . '/users/{user}/images/{imageIdentifier}/shorturls/{id}']]);
        $response->setModel($model);
        // Prevent caching
        $response->setMaxAge(0)->setPrivate();
        $response->headers->addCacheControlDirective('no-store');
    }

Usage Example

Beispiel #1
0
 /**
  * @covers Imbo\Resource\Index::get
  */
 public function testSupportsHttpGet()
 {
     $this->request->expects($this->once())->method('getSchemeAndHttpHost')->will($this->returnValue('http://imbo'));
     $this->request->expects($this->once())->method('getBaseUrl')->will($this->returnValue(''));
     $this->response->expects($this->once())->method('setModel')->with($this->isInstanceOf('Imbo\\Model\\ArrayModel'));
     $this->response->expects($this->once())->method('setMaxAge')->with(0)->will($this->returnSelf());
     $this->response->expects($this->once())->method('setPrivate');
     $responseHeaders = $this->getMock('Symfony\\Component\\HttpFoundation\\ResponseHeaderBag');
     $responseHeaders->expects($this->once())->method('addCacheControlDirective')->with('no-store');
     $this->response->headers = $responseHeaders;
     $this->resource->get($this->event);
 }