/** * Handle GET requests * * @param EventInterface $event 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); }
/** * {@inheritdoc} */ public function formatStatus(Model\Status $model) { $database = (int) $model->getDatabaseStatus(); $storage = (int) $model->getStorageStatus(); return <<<STATUS <?xml version="1.0" encoding="UTF-8"?> <imbo> <status> <date>{$this->dateFormatter->formatDate($model->getDate())}</date> <database>{$database}</database> <storage>{$storage}</storage> </status> </imbo> STATUS; }
/** * @covers Imbo\Model\Status::getData */ public function testGetData() { $date = new DateTime(); $this->model->setDate($date)->setDatabaseStatus(true)->setStorageStatus(true); $this->assertSame(['date' => $date, 'database' => true, 'storage' => true], $this->model->getData()); }
/** * @covers Imbo\Model\Status::getStorageStatus * @covers Imbo\Model\Status::setStorageStatus */ public function testCanSetAndGetStorageStatus() { $this->assertNull($this->model->getStorageStatus()); $this->assertSame($this->model, $this->model->setStorageStatus(true)); $this->assertTrue($this->model->getStorageStatus()); }
/** * {@inheritdoc} */ public function formatStatus(Model\Status $model) { return $this->encode(array('date' => $this->dateFormatter->formatDate($model->getDate()), 'database' => $model->getDatabaseStatus(), 'storage' => $model->getStorageStatus())); }