From 8cd788444f880e0ba8d61889ce38c17dc2171a48 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 21 Dec 2016 10:36:41 +1300 Subject: [PATCH] Mark getObjectFieldName() public, merge in default opts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes we need more granularity over field mapping, e.g. providing a “context” array to a Folder->canCreate() method Rather than calling setValue() on a new Folder instance. --- src/Util/CaseInsensitiveFieldAccessor.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Util/CaseInsensitiveFieldAccessor.php b/src/Util/CaseInsensitiveFieldAccessor.php index 862fe465d..b62ae5562 100644 --- a/src/Util/CaseInsensitiveFieldAccessor.php +++ b/src/Util/CaseInsensitiveFieldAccessor.php @@ -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); };