File tree Expand file tree Collapse file tree 3 files changed +58
-2
lines changed Expand file tree Collapse file tree 3 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
5
5
The format is based on [ Keep a Changelog] [ keepachangelog ] and this project adheres to [ Semantic Versioning] [ semver ] .
6
6
7
+ ## v4.2.0
8
+
9
+ ### Added
10
+
11
+ - Add method to trait ` Metable ` : ` setMetaAttribute `
12
+
7
13
## v4.1.0
8
14
9
15
### Added
Original file line number Diff line number Diff line change @@ -35,19 +35,32 @@ public function meta(): array
35
35
*
36
36
* @return mixed
37
37
*/
38
- public function metaAttribute (string $ key , $ default = null )
38
+ public function metaAttribute (string $ key , mixed $ default = null )
39
39
{
40
40
return Arr::get ($ this ->meta , $ key , $ default );
41
41
}
42
42
43
+ /**
44
+ * @param string $key
45
+ * @param mixed $value
46
+ *
47
+ * @return $this
48
+ */
49
+ public function setMetaAttribute (string $ key , mixed $ value ): static
50
+ {
51
+ Arr::set ($ this ->meta , $ key , $ value );
52
+
53
+ return $ this ;
54
+ }
55
+
43
56
/**
44
57
* Set additional meta information for the element.
45
58
*
46
59
* @param array $meta
47
60
*
48
61
* @return $this
49
62
*/
50
- public function withMeta (array $ meta ): self
63
+ public function withMeta (array $ meta ): static
51
64
{
52
65
$ this ->meta = Arr::merge ($ this ->meta , $ meta );
53
66
Original file line number Diff line number Diff line change @@ -80,6 +80,43 @@ public function testRecursive(): void
80
80
]
81
81
);
82
82
}
83
+
84
+ public function testSetMetaAttribute (): void
85
+ {
86
+ $ instance = new MetableClassTest ();
87
+
88
+ $ instance ->setMetaAttribute ('test ' , 123 );
89
+ static ::assertEquals ($ instance ->metaAttribute ('test ' ), 123 );
90
+
91
+ $ instance ->setMetaAttribute ('params.id ' , 1 );
92
+ $ instance ->setMetaAttribute ('params.isBool ' , true );
93
+ $ instance ->setMetaAttribute ('params.string ' , 'test ' );
94
+ static ::assertEquals (1 , $ instance ->metaAttribute ('params.id ' ));
95
+ static ::assertEquals (true , $ instance ->metaAttribute ('params.isBool ' ));
96
+ static ::assertEquals ('test ' , $ instance ->metaAttribute ('params.string ' ));
97
+
98
+ static ::assertEquals (
99
+ [
100
+ 'id ' => 1 ,
101
+ 'isBool ' => true ,
102
+ 'string ' => 'test ' ,
103
+ ],
104
+ $ instance ->metaAttribute ('params ' )
105
+ );
106
+
107
+ static ::assertEquals (
108
+ [
109
+ 'test ' => 123 ,
110
+ 'params ' =>
111
+ [
112
+ 'id ' => 1 ,
113
+ 'isBool ' => true ,
114
+ 'string ' => 'test ' ,
115
+ ],
116
+ ],
117
+ $ instance ->meta ()
118
+ );
119
+ }
83
120
}
84
121
85
122
/**
You can’t perform that action at this time.
0 commit comments