Skip to content

Commit 8914c34

Browse files
committed
Close #199
1 parent 9f0519b commit 8914c34

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/Schema/RelationshipObject.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* limitations under the License.
1717
*/
1818

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;
2222

2323
/**
2424
* @package Neomerx\JsonApi
@@ -84,11 +84,12 @@ public function __construct(
8484
$isOk ?: Exceptions::throwInvalidArgument('name', $name);
8585

8686
$this->name = $name;
87-
$this->data = $data;
8887
$this->links = $links;
8988
$this->meta = $meta;
9089
$this->isShowData = $isShowData;
9190
$this->isRoot = $isRoot;
91+
92+
$this->setData($data);
9293
}
9394

9495
/**
@@ -110,13 +111,28 @@ public function getData()
110111
if ($this->data instanceof Closure) {
111112
/** @var Closure $data */
112113
$data = $this->data;
113-
$this->data = $data();
114+
$this->setData($data());
114115
}
115116
}
116117

118+
assert(is_array($this->data) === true || is_object($this->data) === true || $this->data === null);
119+
117120
return $this->data;
118121
}
119122

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+
120136
/**
121137
* @inheritdoc
122138
*/

0 commit comments

Comments
 (0)