Fixed FlexIndex keys being lost when FlexCollection gets loaded

This commit is contained in:
Matias Griese
2019-02-13 23:30:35 +02:00
parent 85b4996dbf
commit 09805f7091
5 changed files with 26 additions and 13 deletions

View File

@@ -10,6 +10,7 @@
1. [](#bugfix)
* Fixed validation for select field type with selectize
* Fixed `Flex[class]::getType()` to return the same value in every class
* Fixed `FlexIndex` keys being lost when `FlexCollection` gets loaded
# v1.6.0-rc.2
## 02/07/2019

View File

@@ -59,11 +59,15 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
/**
* @param array $entries
* @param FlexDirectory $directory
* @param string $keyField
* @return static
*/
public static function createFromArray(array $entries, FlexDirectory $directory) : FlexCollectionInterface
public static function createFromArray(array $entries, FlexDirectory $directory, string $keyField = null) : FlexCollectionInterface
{
return new static($entries, $directory);
$instance = new static($entries, $directory);
$instance->setKeyField($keyField);
return $instance;
}
/**

View File

@@ -399,26 +399,28 @@ class FlexDirectory implements FlexAuthorizeInterface
/**
* @param array $entries
* @param string $keyField
* @return FlexCollectionInterface
*/
public function createCollection(array $entries): FlexCollectionInterface
public function createCollection(array $entries, string $keyField = null): FlexCollectionInterface
{
/** @var string|FlexCollectionInterface $className */
$className = $this->collectionClassName ?: $this->getCollectionClass();
return $className::createFromArray($entries, $this);
return $className::createFromArray($entries, $this, $keyField);
}
/**
* @param array $entries
* @param string $keyField
* @return FlexCollectionInterface
*/
public function createIndex(array $entries): FlexCollectionInterface
public function createIndex(array $entries, string $keyField = null): FlexCollectionInterface
{
/** @var string|FlexIndexInterface $className */
$className = $this->indexClassName ?: $this->getIndexClass();
return $className::createFromArray($entries, $this);
return $className::createFromArray($entries, $this, $keyField);
}
/**
@@ -461,11 +463,12 @@ class FlexDirectory implements FlexAuthorizeInterface
/**
* @param array $entries
* @param string $keyField
* @return FlexCollectionInterface
*/
public function loadCollection(array $entries): FlexCollectionInterface
public function loadCollection(array $entries, string $keyField = null): FlexCollectionInterface
{
return $this->createCollection($this->loadObjects($entries));
return $this->createCollection($this->loadObjects($entries), $keyField);
}
/**

View File

@@ -47,11 +47,15 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
/**
* @param array[] $entries
* @param FlexDirectory $directory
* @param string $keyField
* @return static
*/
public static function createFromArray(array $entries, FlexDirectory $directory) : FlexCollectionInterface
public static function createFromArray(array $entries, FlexDirectory $directory, string $keyField = null) : FlexCollectionInterface
{
return new static($entries, $directory);
$instance = new static($entries, $directory);
$instance->setKeyField($keyField);
return $instance;
}
/**
@@ -427,7 +431,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
protected function loadElements(array $entries = null) : array
{
return $this->_flexDirectory->loadObjects($entries ?? $this->withKeyField()->getEntries());
return $this->_flexDirectory->loadObjects($entries ?? $this->getEntries());
}
/**
@@ -436,7 +440,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
protected function loadCollection(array $entries = null) : CollectionInterface
{
return $this->_flexDirectory->loadCollection($entries ?? $this->withKeyField()->getEntries());
return $this->_flexDirectory->loadCollection($entries ?? $this->getEntries(), $this->_keyField);
}
/**

View File

@@ -25,9 +25,10 @@ interface FlexCollectionInterface extends ObjectCollectionInterface, NestedObjec
/**
* @param array $entries
* @param FlexDirectory $directory
* @param string $keyField
* @return static
*/
public static function createFromArray(array $entries, FlexDirectory $directory) : FlexCollectionInterface;
public static function createFromArray(array $entries, FlexDirectory $directory, string $keyField = null) : FlexCollectionInterface;
/**
* @param array $elements