handled case domain not found, also in findbyid
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
1052e00cf5
commit
087db2b2a9
@ -47,9 +47,9 @@ class DomainRepository
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return \App\Entity\Domain
|
||||
* @return false
|
||||
*/
|
||||
public function findByID(int $id): Domain
|
||||
public function findByID(int $id): bool|Domain
|
||||
{
|
||||
$sql = "
|
||||
SELECT id, name, panel_id, a, aaaa
|
||||
@ -60,22 +60,23 @@ class DomainRepository
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':id', var: $id);
|
||||
$statement->execute();
|
||||
$result = $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||
|
||||
return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param String $name
|
||||
*
|
||||
* @return \App\Entity\Domain
|
||||
* @return \App\Entity\Domain|bool
|
||||
*/
|
||||
public function findByName(string $name): Domain
|
||||
public function findByName(string $name): Domain|bool
|
||||
{
|
||||
$sql = "
|
||||
SELECT id, name, panel_id, a, aaaa
|
||||
@ -86,9 +87,13 @@ class DomainRepository
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->execute();
|
||||
$result = $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return new Domain(name: $result['name'], panelID: $result['panel_id'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user