function saveCountry(Country $country) { $data = ["code" => $country->getCode(), "alpha2" => $country->getAlpha2(), "alpha3" => $country->getAlpha3(), "nom_en_gb" => $country->getNomEnGb(), "nom_fr_fr" => $country->getNomFrFr(), "devise" => $country->getDevise(), "taux_tva" => $country->getTauxTva()]; $id = (int) $country->getId(); if ($id === 0) { $this->tableGateway->insert($data); } else { if ($this->getCountry($id)) { $this->tableGateway->update($data, ["id" => $id]); } else { throw new \Exception("Country ID does not exists"); } } }