File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change 16
16
* limitations under the License.
17
17
*/
18
18
19
- use \ Closure ;
20
- use \ Neomerx \JsonApi \Factories \ Exceptions ;
21
- use \ Neomerx \JsonApi \Contracts \ Schema \ RelationshipObjectInterface ;
19
+ use Closure ;
20
+ use Neomerx \JsonApi \Contracts \ Schema \ RelationshipObjectInterface ;
21
+ use Neomerx \JsonApi \Factories \ Exceptions ;
22
22
23
23
/**
24
24
* @package Neomerx\JsonApi
@@ -84,11 +84,12 @@ public function __construct(
84
84
$ isOk ?: Exceptions::throwInvalidArgument ('name ' , $ name );
85
85
86
86
$ this ->name = $ name ;
87
- $ this ->data = $ data ;
88
87
$ this ->links = $ links ;
89
88
$ this ->meta = $ meta ;
90
89
$ this ->isShowData = $ isShowData ;
91
90
$ this ->isRoot = $ isRoot ;
91
+
92
+ $ this ->setData ($ data );
92
93
}
93
94
94
95
/**
@@ -110,13 +111,28 @@ public function getData()
110
111
if ($ this ->data instanceof Closure) {
111
112
/** @var Closure $data */
112
113
$ data = $ this ->data ;
113
- $ this ->data = $ data ();
114
+ $ this ->setData ( $ data () );
114
115
}
115
116
}
116
117
118
+ assert (is_array ($ this ->data ) === true || is_object ($ this ->data ) === true || $ this ->data === null );
119
+
117
120
return $ this ->data ;
118
121
}
119
122
123
+ /**
124
+ * @param object|array|null|Closure $data
125
+ *
126
+ * @return void
127
+ */
128
+ public function setData ($ data )
129
+ {
130
+ assert (is_array ($ data ) === true || $ data instanceof Closure || is_object ($ data ) === true || $ data === null );
131
+
132
+ $ this ->data = $ data ;
133
+ $ this ->isDataEvaluated = false ;
134
+ }
135
+
120
136
/**
121
137
* @inheritdoc
122
138
*/
You can’t perform that action at this time.
0 commit comments