저자: Christer Edvartsen (cogo@starzinger.net)
상속: implements Imbo\Model\ModelInterface
예제 #1
0
파일: Status.php 프로젝트: ASP96/imbo
 /**
  * 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);
 }
예제 #2
0
파일: XML.php 프로젝트: ASP96/imbo
    /**
     * {@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;
    }
예제 #3
0
파일: StatusTest.php 프로젝트: imbo/imbo
 /**
  * @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());
 }
예제 #4
0
파일: StatusTest.php 프로젝트: ASP96/imbo
 /**
  * @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());
 }
예제 #5
0
파일: JSON.php 프로젝트: ASP96/imbo
 /**
  * {@inheritdoc}
  */
 public function formatStatus(Model\Status $model)
 {
     return $this->encode(array('date' => $this->dateFormatter->formatDate($model->getDate()), 'database' => $model->getDatabaseStatus(), 'storage' => $model->getStorageStatus()));
 }