Imbo\Resource\Status::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)
    {
        $response = $event->getResponse();
        $database = $event->getDatabase();
        $storage = $event->getStorage();
        $databaseStatus = $database->getStatus();
        $storageStatus = $storage->getStatus();
        if (!$databaseStatus || !$storageStatus) {
            if (!$databaseStatus && !$storageStatus) {
                $message = 'Database and storage error';
            } else {
                if (!$storageStatus) {
                    $message = 'Storage error';
                } else {
                    $message = 'Database error';
                }
            }
            $response->setStatusCode(503, $message);
        }
        $response->setMaxAge(0)->setPrivate();
        $response->headers->addCacheControlDirective('no-store');
        $statusModel = new Model\Status();
        $statusModel->setDate(new DateTime('now', new DateTimeZone('UTC')))->setDatabaseStatus($databaseStatus)->setStorageStatus($storageStatus);
        $response->setModel($statusModel);
    }

Usage Example

Example #1
0
 /**
  * @covers Imbo\Resource\Status::get
  */
 public function testDoesNotUpdateStatusCodeWhenNoAdapterFails()
 {
     $this->database->expects($this->once())->method('getStatus')->will($this->returnValue(true));
     $this->storage->expects($this->once())->method('getStatus')->will($this->returnValue(true));
     $responseHeaders = $this->getMock('Symfony\\Component\\HttpFoundation\\HeaderBag');
     $responseHeaders->expects($this->once())->method('addCacheControlDirective')->with('no-store');
     $this->response->headers = $responseHeaders;
     $this->response->expects($this->never())->method('setStatusCode');
     $this->response->expects($this->once())->method('setModel')->with($this->isInstanceOf('Imbo\\Model\\Status'));
     $this->response->expects($this->once())->method('setMaxAge')->with(0)->will($this->returnSelf());
     $this->response->expects($this->once())->method('setPrivate')->will($this->returnSelf());
     $this->resource->get($this->event);
 }