Skip to content

Commit

Permalink
Work around document constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
abellion committed Sep 15, 2017
1 parent 70749e7 commit b794d5f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ public function has(string $offset)
*/
public function with(array $fields)
{
$document = [];
$document = new static();
$document->document = [];

foreach ($fields as $field) {
if (array_key_exists($field, $this->document)) {
$document[$field] = $this->document[$field];
$document->document[$field] = $this->document[$field];
}
}

return new static($document);
return $document;
}

/**
Expand All @@ -96,15 +97,16 @@ public function with(array $fields)
*/
public function without(array $fields)
{
$document = [];
$document = new static();
$document->document = [];

foreach ($this->document as $key => $value) {
if (!in_array($key, $fields)) {
$document[$key] = $this->document[$key];
$document->document[$key] = $this->document[$key];
}
}

return new static($document);
return $document;
}


Expand Down

0 comments on commit b794d5f

Please sign in to comment.