mirror of
https://github.com/getgrav/grav.git
synced 2026-03-04 03:21:33 +01:00
Flex: Added support for custom object index classes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user