Skip to content

Commit

Permalink
Merge pull request silverstripe#31 from open-sausages/pulls/case-acce…
Browse files Browse the repository at this point in the history
…ssor-merge

Improve CaseInsensitiveFieldAccessor
  • Loading branch information
Damian Mooyman authored Dec 20, 2016
2 parents 1d25c4f + 8cd7884 commit 7db5bac
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Util/CaseInsensitiveFieldAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public function getValue(ViewableData $object, $fieldName, $opts = [])
public function setValue(ViewableData $object, $fieldName, $value, $opts = [])
{
$opts = $opts ?: [];
$opts = [
self::HAS_METHOD => true,
self::HAS_FIELD => true,
self::HAS_SETTER => true,
self::DATAOBJECT => true,
] + $opts;
$opts = array_merge([
self::HAS_METHOD => true,
self::HAS_FIELD => true,
self::HAS_SETTER => true,
self::DATAOBJECT => true,
], $opts);

$objectFieldName = $this->getObjectFieldName($object, $fieldName, $opts);

Expand Down Expand Up @@ -122,8 +122,16 @@ public function setValue(ViewableData $object, $fieldName, $value, $opts = [])
* Example: [ViewableDataCaseInsensitiveFieldMapper::HAS_METHOD => true]
* @return null|string Name in actual casing on $object
*/
protected function getObjectFieldName(ViewableData $object, $fieldName, $opts = [])
public function getObjectFieldName(ViewableData $object, $fieldName, $opts = [])
{
$opts = $opts ?: [];
$opts = array_merge([
self::HAS_METHOD => true,
self::HAS_FIELD => true,
self::HAS_SETTER => true,
self::DATAOBJECT => true,
], $opts);

$optFn = function ($type) use (&$opts) {
return (in_array($type, $opts) && $opts[$type] === true);
};
Expand Down

0 comments on commit 7db5bac

Please sign in to comment.