diff --git a/CHANGELOG.md b/CHANGELOG.md index a3241dbc3..1afd89378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Added `Content-Type: application/json` body support for PSR-7 `ServerRequest` 1. [](#bugfix) * Fixed `Undefined method closure::fields()` when getting avatar for user, thanks @Romarain [#2422](https://github.com/getgrav/grav/issues/2422) + * Grav 1.6: Added `Flex[Class]::getFlexType()` to all flex classes to have the interface for all Flex classes # v1.6.0-rc.4 ## 03/20/2019 diff --git a/system/src/Grav/Framework/Flex/Flex.php b/system/src/Grav/Framework/Flex/Flex.php index de5ddcd26..8f47c46bf 100644 --- a/system/src/Grav/Framework/Flex/Flex.php +++ b/system/src/Grav/Framework/Flex/Flex.php @@ -63,7 +63,7 @@ class Flex implements \Countable */ public function addDirectory(FlexDirectory $directory) { - $this->types[$directory->getType()] = $directory; + $this->types[$directory->getFlexType()] = $directory; return $this; } diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php index a71ff604e..86671bdc2 100644 --- a/system/src/Grav/Framework/Flex/FlexCollection.php +++ b/system/src/Grav/Framework/Flex/FlexCollection.php @@ -87,7 +87,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface parent::__construct($entries); if ($directory) { - $this->setFlexDirectory($directory)->setKey($directory->getType()); + $this->setFlexDirectory($directory)->setKey($directory->getFlexType()); } } @@ -129,7 +129,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface */ public function getFlexType(): string { - return $this->_flexDirectory->getType(); + return $this->_flexDirectory->getFlexType(); } /** diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index d91b5564b..7b50a7eed 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -91,8 +91,19 @@ class FlexDirectory implements FlexAuthorizeInterface /** * @return string + * @deprecated 1.6 Use ->getFlexType() method instead. */ public function getType(): string + { + user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use ->getFlexType() method instead', E_USER_DEPRECATED); + + return $this->type; + } + + /** + * @return string + */ + public function getFlexType(): string { return $this->type; } @@ -102,7 +113,7 @@ class FlexDirectory implements FlexAuthorizeInterface */ public function getTitle(): string { - return $this->getBlueprintInternal()->get('title', ucfirst($this->getType())); + return $this->getBlueprintInternal()->get('title', ucfirst($this->getFlexType())); } /** @@ -312,13 +323,13 @@ class FlexDirectory implements FlexAuthorizeInterface if (Utils::isAdminPlugin()) { $key = substr($key, 0, -1); } - $cache = new DoctrineCache($gravCache->getCacheDriver(), 'flex-objects-' . $this->getType() . $key, $timeout); + $cache = new DoctrineCache($gravCache->getCacheDriver(), 'flex-objects-' . $this->getFlexType() . $key, $timeout); } catch (\Exception $e) { /** @var Debugger $debugger */ $debugger = Grav::instance()['debugger']; $debugger->addException($e); - $cache = new MemoryCache('flex-objects-' . $this->getType()); + $cache = new MemoryCache('flex-objects-' . $this->getFlexType()); } // Disable cache key validation. diff --git a/system/src/Grav/Framework/Flex/FlexForm.php b/system/src/Grav/Framework/Flex/FlexForm.php index 3e4d8265b..5cf079c19 100644 --- a/system/src/Grav/Framework/Flex/FlexForm.php +++ b/system/src/Grav/Framework/Flex/FlexForm.php @@ -45,7 +45,7 @@ class FlexForm implements FlexFormInterface { $this->name = $name; $this->form = $form; - $uniqueId = $object->exists() ? $object->getStorageKey() : "{$object->getType()}:new"; + $uniqueId = $object->exists() ? $object->getStorageKey() : "{$object->getFlexType()}:new"; $this->setObject($object); $this->setId($this->getName()); $this->setUniqueId(md5($uniqueId)); @@ -73,7 +73,7 @@ class FlexForm implements FlexFormInterface $object = $this->getObject(); $name = $this->name ?: 'object'; - return "flex-{$object->getType()}-{$name}"; + return "flex-{$object->getFlexType()}-{$name}"; } /** @@ -101,6 +101,14 @@ class FlexForm implements FlexFormInterface return $value ?? $this->getObject()->value($name); } + /** + * @return string + */ + public function getFlexType(): string + { + return $this->object->getFlexType(); + } + /** * @return FlexObjectInterface */ diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index 77a2d85ac..9fa1a603c 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -104,7 +104,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde */ public function getFlexType(): string { - return $this->_flexDirectory->getType(); + return $this->_flexDirectory->getFlexType(); } /** @@ -171,7 +171,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde { // Get storage keys for the objects. $keys = []; - $type = $this->_flexDirectory->getType() . '.obj:'; + $type = $this->_flexDirectory->getFlexType() . '.obj:'; foreach ($this->getEntries() as $key => $value) { $keys[$key] = $value['flex_key'] ?? $type . $value['storage_key']; @@ -191,7 +191,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde return $this; } - $type = $keyField === 'flex_key' ? $this->_flexDirectory->getType() . '.obj:' : ''; + $type = $keyField === 'flex_key' ? $this->_flexDirectory->getFlexType() . '.obj:' : ''; $entries = []; foreach ($this->getEntries() as $key => $value) { if (!isset($value['key'])) { diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index 4c8882187..78cbcfed5 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -115,7 +115,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface */ public function getFlexType(): string { - return $this->_flexDirectory->getType(); + return $this->_flexDirectory->getFlexType(); } /** @@ -186,7 +186,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface */ public function getFlexKey(): string { - return $this->_storage['flex_key'] ?? $this->_flexDirectory->getType() . '.obj:' . $this->getStorageKey(); + return $this->_storage['flex_key'] ?? $this->_flexDirectory->getFlexType() . '.obj:' . $this->getStorageKey(); } /**