Skip to content

Commit

Permalink
Close neomerx#199
Browse files Browse the repository at this point in the history
  • Loading branch information
neomerx committed Feb 21, 2018
1 parent 9f0519b commit 8914c34
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/Schema/RelationshipObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* limitations under the License.
*/

use \Closure;
use \Neomerx\JsonApi\Factories\Exceptions;
use \Neomerx\JsonApi\Contracts\Schema\RelationshipObjectInterface;
use Closure;
use Neomerx\JsonApi\Contracts\Schema\RelationshipObjectInterface;
use Neomerx\JsonApi\Factories\Exceptions;

/**
* @package Neomerx\JsonApi
Expand Down Expand Up @@ -84,11 +84,12 @@ public function __construct(
$isOk ?: Exceptions::throwInvalidArgument('name', $name);

$this->name = $name;
$this->data = $data;
$this->links = $links;
$this->meta = $meta;
$this->isShowData = $isShowData;
$this->isRoot = $isRoot;

$this->setData($data);
}

/**
Expand All @@ -110,13 +111,28 @@ public function getData()
if ($this->data instanceof Closure) {
/** @var Closure $data */
$data = $this->data;
$this->data = $data();
$this->setData($data());
}
}

assert(is_array($this->data) === true || is_object($this->data) === true || $this->data === null);

return $this->data;
}

/**
* @param object|array|null|Closure $data
*
* @return void
*/
public function setData($data)
{
assert(is_array($data) === true || $data instanceof Closure || is_object($data) === true || $data === null);

$this->data = $data;
$this->isDataEvaluated = false;
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit 8914c34

Please sign in to comment.