Skip to content

Commit

Permalink
[update] move to onlyField group of methods
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov committed Aug 5, 2020
1 parent 35e1f92 commit 1132e47
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,19 +577,22 @@ public function allFields()
return $this;
}

private function checkOnlyFieldsField(string $field)
private function checkOnlyFieldsField(string $fieldName)
{
$this->getField($field); // test if field exists
$field = $this->getField($fieldName); // test if field exists

if ($this->only_fields) {
if (!in_array($field, $this->only_fields, true) && !$this->getField($field)->system) {
throw (new Exception('Attempt to use field outside of those set by onlyFields'))
->addMoreInfo('field', $field)
->addMoreInfo('only_fields', $this->only_fields);
}
if (!$this->isOnlyField($fieldName) && !$field->system) {
throw (new Exception('Attempt to use field outside of those set by onlyFields'))
->addMoreInfo('field', $fieldName)
->addMoreInfo('only_fields', $this->only_fields);
}
}

public function isOnlyField(string $fieldName)
{
return !$this->only_fields || in_array($fieldName, $this->only_fields, true);
}

/**
* Will return true if specified field is dirty.
*/
Expand Down Expand Up @@ -663,11 +666,6 @@ public function getFields($filter = null): array
}, ARRAY_FILTER_USE_BOTH);
}

public function isOnlyField($fieldName)
{
return !$this->only_fields || in_array($fieldName, $this->only_fields, true);
}

/**
* Set field value.
*
Expand Down

0 comments on commit 1132e47

Please sign in to comment.