9
9
use MongoDB \Model \BSONArray ;
10
10
use UnexpectedValueException ;
11
11
12
- use function array_search ;
13
12
use function getenv ;
14
13
use function var_dump ;
15
14
@@ -21,10 +20,10 @@ class PersistableEntry implements Persistable
21
20
private $ id ;
22
21
23
22
/** @var string */
24
- private $ name ;
23
+ public $ name ;
25
24
26
25
/** @var array<PersistableEmail> */
27
- private $ emails = [];
26
+ public $ emails = [];
28
27
29
28
public function __construct (string $ name )
30
29
{
@@ -37,36 +36,6 @@ public function getId(): ObjectId
37
36
return $ this ->id ;
38
37
}
39
38
40
- public function getName (): string
41
- {
42
- return $ this ->name ;
43
- }
44
-
45
- public function setName (string $ name ): void
46
- {
47
- $ this ->name = $ name ;
48
- }
49
-
50
- public function getEmails (): array
51
- {
52
- return $ this ->emails ;
53
- }
54
-
55
- public function addEmail (PersistableEmail $ email ): void
56
- {
57
- $ this ->emails [] = $ email ;
58
- }
59
-
60
- public function deleteEmail (PersistableEmail $ email ): void
61
- {
62
- $ index = array_search ($ email , $ this ->emails , true );
63
- if ($ index === false ) {
64
- return ;
65
- }
66
-
67
- unset($ this ->emails [$ index ]);
68
- }
69
-
70
39
public function bsonSerialize (): object
71
40
{
72
41
return (object ) [
@@ -97,27 +66,17 @@ public function bsonUnserialize(array $data): void
97
66
class PersistableEmail implements Persistable
98
67
{
99
68
/** @var string */
100
- private $ type ;
69
+ public $ type ;
101
70
102
71
/** @var string */
103
- private $ address ;
72
+ public $ address ;
104
73
105
74
public function __construct (string $ type , string $ address )
106
75
{
107
76
$ this ->type = $ type ;
108
77
$ this ->address = $ address ;
109
78
}
110
79
111
- public function getType (): string
112
- {
113
- return $ this ->type ;
114
- }
115
-
116
- public function getAddress (): string
117
- {
118
- return $ this ->address ;
119
- }
120
-
121
80
public function bsonSerialize (): object
122
81
{
123
82
return (object ) [
@@ -134,8 +93,8 @@ public function bsonUnserialize(array $data): void
134
93
}
135
94
136
95
$ entry = new PersistableEntry ('alcaeus ' );
137
- $ entry->
addEmail ( new PersistableEmail (
'work ' ,
'[email protected] ' ) );
138
- $ entry->
addEmail ( new PersistableEmail (
'private ' ,
'[email protected] ' ) );
96
+ $ entry->
emails [] = new PersistableEmail (
'work ' ,
'[email protected] ' );
97
+ $ entry->
emails [] = new PersistableEmail (
'private ' ,
'[email protected] ' );
139
98
140
99
$ client = new Client (getenv ('MONGODB_URI ' ) ?: 'mongodb://127.0.0.1/ ' );
141
100
0 commit comments