diff --git a/CHANGELOG.md b/CHANGELOG.md index 15163478e..82cae9dc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [](#new) * Added `select()` and `unselect()` methods to `CollectionInterface` and its base classes * Added `orderBy()` and `limit()` methods to `ObjectCollectionInterface` and its base classes + * Flex: Added support for custom object index classes 1. [](#improved) * Improve Flex storage 1. [](#bugfix) diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index da736527d..3e38aa9b9 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -60,6 +60,8 @@ class FlexDirectory implements FlexAuthorizeInterface protected $objectClassName; /** @var string */ protected $collectionClassName; + /** @var string */ + protected $indexClassName; /** * FlexDirectory constructor. @@ -397,14 +399,26 @@ class FlexDirectory implements FlexAuthorizeInterface return new $className($entries, $this); } + /** + * @param array $entries + * @return FlexCollection + */ + public function createIndex(array $entries) : CollectionInterface + { + $className = $this->indexClassName ?: $this->getIndexClass(); + + return new $className($entries, $this); + } + /** * @return string */ public function getObjectClass() : string { if (!$this->objectClassName) { - $this->objectClassName = $this->getConfig('data.object', 'Grav\\Plugin\\FlexObjects\\FlexObject'); + $this->objectClassName = $this->getConfig('data.object', 'Grav\\Framework\\Flex\\FlexObject'); } + return $this->objectClassName; } @@ -415,11 +429,25 @@ class FlexDirectory implements FlexAuthorizeInterface public function getCollectionClass() : string { if (!$this->collectionClassName) { - $this->collectionClassName = $this->getConfig('data.collection', 'Grav\\Plugin\\FlexObjects\\FlexCollection'); + $this->collectionClassName = $this->getConfig('data.collection', 'Grav\\Framework\\Flex\\FlexCollection'); } + return $this->collectionClassName; } + + /** + * @return string + */ + public function getIndexClass() : string + { + if (!$this->indexClassName) { + $this->indexClassName = $this->getConfig('data.index', 'Grav\\Framework\\Flex\\FlexIndex'); + } + + return $this->indexClassName; + } + /** * @param array $entries * @return FlexCollection @@ -584,7 +612,7 @@ class FlexDirectory implements FlexAuthorizeInterface } // We need to do this in two steps as orderBy() calls loadIndex() again and we do not want infinite loop. - $this->index = new FlexIndex($keys, $this); + $this->index = $this->createIndex($keys); $this->index = $this->index->orderBy($this->getConfig('data.ordering', [])); $debugger->stopTimer('flex-keys-' . $this->type . $j);