|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LibraryCatalog\Entity; |
|
6
|
|
|
|
|
7
|
|
|
class Author |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var mixed */ |
|
10
|
|
|
public $id; |
|
11
|
|
|
/** @var string */ |
|
12
|
|
|
public string $name; |
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
public string $birthdate; |
|
15
|
|
|
/** @var string */ |
|
16
|
|
|
public ?string $deathdate; |
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
public ?string $biography; |
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
public ?string $summary; |
|
21
|
|
|
/** @var Book[] */ |
|
22
|
|
|
public array $books; |
|
23
|
|
|
|
|
24
|
|
|
/** @var bool */ |
|
25
|
|
|
protected bool $areBooksLoaded = false; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $name |
|
29
|
|
|
* @param string $birthdate |
|
30
|
|
|
* @param string $deathdate |
|
31
|
|
|
* @param string $biography |
|
32
|
|
|
* @param string $summary |
|
33
|
|
|
* @return Author |
|
34
|
|
|
*/ |
|
35
|
10 |
|
public static function create( |
|
36
|
|
|
string $name, |
|
37
|
|
|
string $birthdate, |
|
38
|
|
|
string $deathdate = null, |
|
39
|
|
|
string $biography = null, |
|
40
|
|
|
string $summary = null |
|
41
|
|
|
): Author { |
|
42
|
10 |
|
$author = new static(); |
|
43
|
|
|
|
|
44
|
10 |
|
$author->name = $name; |
|
45
|
10 |
|
$author->birthdate = $birthdate; |
|
46
|
10 |
|
$author->deathdate = $deathdate; |
|
47
|
10 |
|
$author->biography = $biography; |
|
48
|
10 |
|
$author->summary = $summary; |
|
49
|
|
|
|
|
50
|
10 |
|
return $author; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param array $data |
|
55
|
|
|
* @return Author |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function fill(array $data): Author |
|
58
|
|
|
{ |
|
59
|
1 |
|
if (isset($data['name'])) { |
|
60
|
1 |
|
$this->name = (string)$data['name']; |
|
61
|
|
|
} |
|
62
|
1 |
|
if (isset($data['birthdate'])) { |
|
63
|
1 |
|
$this->birthdate = (string)$data['birthdate']; |
|
64
|
|
|
} |
|
65
|
1 |
|
if (isset($data['deathdate'])) { |
|
66
|
1 |
|
$this->deathdate = (string)$data['deathdate']; |
|
67
|
|
|
} |
|
68
|
1 |
|
if (isset($data['biography'])) { |
|
69
|
1 |
|
$this->biography = (string)$data['biography']; |
|
70
|
|
|
} |
|
71
|
1 |
|
if (isset($data['summary'])) { |
|
72
|
1 |
|
$this->summary = (string)$data['summary']; |
|
73
|
|
|
} |
|
74
|
1 |
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return bool |
|
79
|
|
|
*/ |
|
80
|
8 |
|
public function areBooksLoaded(): bool |
|
81
|
|
|
{ |
|
82
|
8 |
|
return $this->areBooksLoaded; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param Book[] $books |
|
87
|
|
|
* @return Author |
|
88
|
|
|
*/ |
|
89
|
3 |
|
public function setBooks(array $books): Author |
|
90
|
|
|
{ |
|
91
|
3 |
|
$this->books = $books; |
|
92
|
3 |
|
$this->areBooksLoaded = true; |
|
93
|
|
|
|
|
94
|
3 |
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|