From 95c58c83617d911904b2bcf01efa06eaf97e4bf0 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 12 Jul 2019 12:40:23 +0300 Subject: [PATCH] `FlexDirectory::getObject()` can now be called without any parameters to create a new object --- CHANGELOG.md | 1 + system/src/Grav/Framework/Flex/FlexDirectory.php | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 769ac0964..399324517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 1. [](#improved) * Better support for Symfony local server `symfony server:start` * Make `Route` objects immutable + * `FlexDirectory::getObject()` can now be called without any parameters to create a new object 1. [](#bugfix) * Fixed `Form` not to use deleted flash object until the end of the request fixing issues with reset * Fixed `FlexForm` to allow multiple form instances with non-existing objects diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index c75a90152..bc48367b6 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -222,7 +222,7 @@ class FlexDirectory implements FlexAuthorizeInterface } /** - * Returns an object if it exists. + * Returns an object if it exists. If no arguments are passed (or both of them are null), method creates a new empty object. * * Note: It is not safe to use the object without checking if the user can access it. * @@ -230,8 +230,12 @@ class FlexDirectory implements FlexAuthorizeInterface * @param string|null $keyField Field to be used as the key. * @return FlexObjectInterface|null */ - public function getObject($key, string $keyField = null): ?FlexObjectInterface + public function getObject($key = null, string $keyField = null): ?FlexObjectInterface { + if (null === $key && null === $keyField) { + return $this->createObject([], ''); + } + return $this->getIndex(null, $keyField)->get($key); }