diff --git a/composer.json b/composer.json index 951fc70..67faec8 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "dusank/knapsack", + "name": "martinvenus/knapsack", "license": "MIT", "type": "library", "description": "Collection library for PHP", diff --git a/src/Collection.php b/src/Collection.php index f8037a0..467b2b7 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -95,6 +95,7 @@ public static function range($start = 0, $end = null, $step = 1) * {@inheritdoc} * @throws InvalidReturnValue */ + #[\ReturnTypeWillChange] public function getIterator() { if ($this->inputFactory) { @@ -131,6 +132,18 @@ function ($value, $key) { ); } + public function __serialize() + { + return toArray( + map( + $this->input, + function ($value, $key) { + return [$key, $value]; + } + ) + ); + } + /** * {@inheritdoc} */ @@ -138,4 +151,9 @@ public function unserialize($serialized) { $this->input = dereferenceKeyValue(unserialize($serialized)); } + + public function __unserialize($data) + { + $this->input = dereferenceKeyValue($data); + } }