Beispiel #1
0
 public function db() : Sqlite3
 {
     if (!$this->db) {
         $db = new Sqlite3($this->dbPath, SQLITE3_OPEN_READWRITE);
         $openErr = $db->lastErrorCode();
         if ($openErr) {
             throw new Exception($db->lastErrorMsg());
         }
         $db->enableExceptions(true);
         $this->db = $db;
     }
     return $this->db;
 }
Beispiel #2
0
 public function __invoke()
 {
     $root = __DIR__ . '/..';
     $db = new Sqlite3($root . '/db/data.sqlite3', SQLITE3_OPEN_READWRITE);
     $openErr = $db->lastErrorCode();
     if ($openErr) {
         throw new Exception($db->lastErrorMsg());
     }
     $db->enableExceptions(true);
     $stmt = $db->prepare(self::QUERY_SOLDIERS_LIST);
     $result = $stmt->execute();
     /**
      * @var $soldierList Soldier[]
      */
     $soldierList = [];
     while ($record = $result->fetchArray(SQLITE3_ASSOC)) {
         $soldierIdentity = new SoldierIdentity($record['firstName'], $record['lastName'], $record['nickName'], $record['nationality']);
         $soliderServiceRecord = new SoldierServiceRecord($record['status'], $record['rank'], $record['specialization'], $record['numMissions'], $record['numKills'], $record['hp'], $record['will'], $record['defence'], $record['aim']);
         $soldierList[] = new Soldier($soldierIdentity, $soliderServiceRecord);
     }
     $this->response->setBody((new TemplateFactory([$root . '/tpl']))->loadTemplate('home.twig')->render(['soldierList' => $soldierList]));
 }