mirror of
https://github.com/standardebooks/web.git
synced 2025-07-18 20:36:38 -04:00
Standardize trim and other validation of nullable and non-nullable properties
This commit is contained in:
parent
0eaf2e8e47
commit
85307a7c7e
21 changed files with 347 additions and 16 deletions
|
@ -1,4 +1,7 @@
|
|||
<?
|
||||
|
||||
use Safe\DateTimeImmutable;
|
||||
|
||||
class EbookSource{
|
||||
public ?int $EbookSourceId = null;
|
||||
public ?int $EbookId = null;
|
||||
|
@ -12,7 +15,40 @@ class EbookSource{
|
|||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exceptions\ValidationException
|
||||
*/
|
||||
public function Validate(): void{
|
||||
/** @throws void */
|
||||
$now = new DateTimeImmutable();
|
||||
|
||||
$error = new Exceptions\ValidationException();
|
||||
|
||||
if(!isset($this->EbookId)){
|
||||
$error->Add(new Exceptions\EbookSourceEbookIdRequiredException());
|
||||
}
|
||||
|
||||
if(isset($this->Url)){
|
||||
$this->Url = trim($this->Url);
|
||||
|
||||
if($this->Url == ''){
|
||||
$error->Add(new Exceptions\EbookSourceUrlRequiredException());
|
||||
}
|
||||
}
|
||||
else{
|
||||
$error->Add(new Exceptions\EbookSourceUrlRequiredException());
|
||||
}
|
||||
|
||||
if($error->HasExceptions){
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exceptions\ValidationException
|
||||
*/
|
||||
public function Create(): void{
|
||||
$this->Validate();
|
||||
Db::Query('
|
||||
INSERT into EbookSources (EbookId, Type, Url)
|
||||
values (?,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue