diff --git a/CHANGELOG.md b/CHANGELOG.md index 552d7bfc..dcb40c53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). +## [3.3.9](https://github.com/packlink-dev/ecommerce_module_core/compare/v3.3.8...v3.3.9) - 2022-05-30 +### Added +- Added `__serialize` and `__unserialize` methods to `Serializable` interface in order to add compatibility with PHP8.1. +- Implemented `__serialize` and `__unserialize` methods in all classes that implement `Serializable` interface. + ## [3.3.8](https://github.com/packlink-dev/ecommerce_module_core/compare/v3.3.7...v3.3.8) - 2022-05-09 ### Added - Added carrier logos for Colis Prive and Shop2Shop shipping services. diff --git a/src/BusinessLogic/Scheduler/ScheduleCheckTask.php b/src/BusinessLogic/Scheduler/ScheduleCheckTask.php index 3f46c58b..6586cee2 100644 --- a/src/BusinessLogic/Scheduler/ScheduleCheckTask.php +++ b/src/BusinessLogic/Scheduler/ScheduleCheckTask.php @@ -49,6 +49,21 @@ public function toArray() return array(); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + } + /** * Runs task logic. * diff --git a/src/BusinessLogic/Tasks/BatchTaskCleanupTask.php b/src/BusinessLogic/Tasks/BatchTaskCleanupTask.php index 978ad6d3..1211872d 100644 --- a/src/BusinessLogic/Tasks/BatchTaskCleanupTask.php +++ b/src/BusinessLogic/Tasks/BatchTaskCleanupTask.php @@ -87,6 +87,23 @@ public static function fromArray(array $array) return new static($array['taskStatuses'], $array['taskTypes']); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->taskStatuses = $data['taskStatuses']; + $this->taskTypes = $data['taskTypes']; + } + /** * Executes the task. * diff --git a/src/BusinessLogic/Tasks/GetDefaultParcelAndWarehouseTask.php b/src/BusinessLogic/Tasks/GetDefaultParcelAndWarehouseTask.php index da69f38f..855b0bf0 100644 --- a/src/BusinessLogic/Tasks/GetDefaultParcelAndWarehouseTask.php +++ b/src/BusinessLogic/Tasks/GetDefaultParcelAndWarehouseTask.php @@ -35,6 +35,21 @@ public function toArray() return array(); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + } + /** * Runs task logic. * diff --git a/src/BusinessLogic/Tasks/SendDraftTask.php b/src/BusinessLogic/Tasks/SendDraftTask.php index 89de2557..2f21f1c6 100644 --- a/src/BusinessLogic/Tasks/SendDraftTask.php +++ b/src/BusinessLogic/Tasks/SendDraftTask.php @@ -80,6 +80,22 @@ public function toArray() return array('order_id' => $this->orderId); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->orderId = $data['order_id']; + } + /** * String representation of object * diff --git a/src/BusinessLogic/Tasks/TaskCleanupTask.php b/src/BusinessLogic/Tasks/TaskCleanupTask.php index b472d386..4a42105e 100644 --- a/src/BusinessLogic/Tasks/TaskCleanupTask.php +++ b/src/BusinessLogic/Tasks/TaskCleanupTask.php @@ -88,6 +88,24 @@ public function toArray() ); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->taskType = $data['task_type']; + $this->taskStatuses = $data['task_statuses']; + $this->taskAge = $data['task_age']; + } + /** * @inheritdoc */ diff --git a/src/BusinessLogic/Tasks/UpdateShipmentDataTask.php b/src/BusinessLogic/Tasks/UpdateShipmentDataTask.php index c050cc11..8a85aa92 100644 --- a/src/BusinessLogic/Tasks/UpdateShipmentDataTask.php +++ b/src/BusinessLogic/Tasks/UpdateShipmentDataTask.php @@ -113,6 +113,25 @@ public function toArray() ); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->progress = $data['progress']; + $this->progressStep = $data['progress_step']; + $this->references = $data['references']; + $this->orderStatuses = $data['order_statuses']; + } + /** * @inheritdoc */ diff --git a/src/BusinessLogic/Tasks/UpdateShippingServicesTask.php b/src/BusinessLogic/Tasks/UpdateShippingServicesTask.php index 5c60bb7e..809206b4 100644 --- a/src/BusinessLogic/Tasks/UpdateShippingServicesTask.php +++ b/src/BusinessLogic/Tasks/UpdateShippingServicesTask.php @@ -50,6 +50,21 @@ public function toArray() return array(); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + } + /** * Gets all local methods and remote services and synchronizes data. * diff --git a/src/Infrastructure/AutoTest/AutoTestTask.php b/src/Infrastructure/AutoTest/AutoTestTask.php index 78a42f19..ed530eb8 100644 --- a/src/Infrastructure/AutoTest/AutoTestTask.php +++ b/src/Infrastructure/AutoTest/AutoTestTask.php @@ -53,6 +53,22 @@ public function toArray() return array('data' => $this->data); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->data = $data['data']; + } + /** * String representation of object. * diff --git a/src/Infrastructure/Serializer/Concrete/JsonSerializer.php b/src/Infrastructure/Serializer/Concrete/JsonSerializer.php index d270b03e..e5be7d2e 100644 --- a/src/Infrastructure/Serializer/Concrete/JsonSerializer.php +++ b/src/Infrastructure/Serializer/Concrete/JsonSerializer.php @@ -20,7 +20,7 @@ class JsonSerializer extends Serializer */ protected function doSerialize($data) { - if (!method_exists($data, 'toArray')) { + if (!in_array(gettype($data), ['object', 'string'], true) || !method_exists($data, 'toArray')) { if ($data instanceof \stdClass) { $data->className = get_class($data); } diff --git a/src/Infrastructure/Serializer/Interfaces/Serializable.php b/src/Infrastructure/Serializer/Interfaces/Serializable.php index 435b2d5d..e9269a15 100644 --- a/src/Infrastructure/Serializer/Interfaces/Serializable.php +++ b/src/Infrastructure/Serializer/Interfaces/Serializable.php @@ -25,4 +25,16 @@ public static function fromArray(array $array); * @return array Array representation of a serializable object. */ public function toArray(); + + /** + * @return array + */ + public function __serialize(); + + /** + * @param array $data + * + * @return void + */ + public function __unserialize($data); } \ No newline at end of file diff --git a/src/Infrastructure/TaskExecution/AsyncBatchStarter.php b/src/Infrastructure/TaskExecution/AsyncBatchStarter.php index 3125aaee..721dd2d4 100644 --- a/src/Infrastructure/TaskExecution/AsyncBatchStarter.php +++ b/src/Infrastructure/TaskExecution/AsyncBatchStarter.php @@ -109,6 +109,36 @@ public function toArray() ); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->batchSize = $data['batchSize']; + $this->addIndex = $data['addIndex']; + + $runners = array(); + $subBatches = array(); + foreach ($data['runners'] as $runner) { + $runners[] = Serializer::unserialize($runner); + } + + foreach ($data['subBatches'] as $subBatch) { + $subBatches[] = Serializer::unserialize($subBatch); + } + + $this->runners = $runners; + $this->subBatches = $subBatches; + } + /** * AsyncBatchStarter constructor. * diff --git a/src/Infrastructure/TaskExecution/CompositeTask.php b/src/Infrastructure/TaskExecution/CompositeTask.php index 46b264eb..68cbd4d4 100644 --- a/src/Infrastructure/TaskExecution/CompositeTask.php +++ b/src/Infrastructure/TaskExecution/CompositeTask.php @@ -106,6 +106,33 @@ public function toArray() ); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->initialProgress = $data['initial_progress']; + $this->taskProgressMap = $data['task_progress_map']; + $this->tasksProgressShare = $data['tasks_progress_share']; + + $tasks = array(); + foreach ($data['tasks'] as $task) { + $tasks[] = Serializer::serialize($task); + } + + $this->tasks = $tasks; + + $this->registerSubTasksEvents(); + } + /** * @inheritdoc */ diff --git a/src/Infrastructure/TaskExecution/QueueItemStarter.php b/src/Infrastructure/TaskExecution/QueueItemStarter.php index b856e299..5bc2bbb0 100644 --- a/src/Infrastructure/TaskExecution/QueueItemStarter.php +++ b/src/Infrastructure/TaskExecution/QueueItemStarter.php @@ -67,6 +67,22 @@ public function toArray() return array('queue_item_id' => $this->queueItemId); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->queueItemId = $data['queue_item_id']; + } + /** * @inheritdoc */ diff --git a/src/Infrastructure/TaskExecution/TaskRunnerStarter.php b/src/Infrastructure/TaskExecution/TaskRunnerStarter.php index 563c2ec2..1fbdc4b4 100644 --- a/src/Infrastructure/TaskExecution/TaskRunnerStarter.php +++ b/src/Infrastructure/TaskExecution/TaskRunnerStarter.php @@ -78,6 +78,22 @@ public function toArray() return array('guid' => $this->guid); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->guid = $data['guid']; + } + /** * String representation of object. * diff --git a/tests/Infrastructure/Common/TestComponents/TaskExecution/AbortTask.php b/tests/Infrastructure/Common/TestComponents/TaskExecution/AbortTask.php index 6b42ddd9..831ad821 100644 --- a/tests/Infrastructure/Common/TestComponents/TaskExecution/AbortTask.php +++ b/tests/Infrastructure/Common/TestComponents/TaskExecution/AbortTask.php @@ -32,4 +32,19 @@ public function toArray() { return array(); } + + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + } } diff --git a/tests/Infrastructure/Common/TestComponents/TaskExecution/FakeRunnable.php b/tests/Infrastructure/Common/TestComponents/TaskExecution/FakeRunnable.php index 7d7e1e21..3c99c03b 100644 --- a/tests/Infrastructure/Common/TestComponents/TaskExecution/FakeRunnable.php +++ b/tests/Infrastructure/Common/TestComponents/TaskExecution/FakeRunnable.php @@ -59,6 +59,23 @@ public function toArray() ); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->testProperty = $data['testProperty']; + $this->callHistory = $data['callHistory']; + } + /** * Starts runnable run logic. */ diff --git a/tests/Infrastructure/Common/TestComponents/TaskExecution/FooTask.php b/tests/Infrastructure/Common/TestComponents/TaskExecution/FooTask.php index 86b05246..ed96fbd2 100644 --- a/tests/Infrastructure/Common/TestComponents/TaskExecution/FooTask.php +++ b/tests/Infrastructure/Common/TestComponents/TaskExecution/FooTask.php @@ -58,6 +58,24 @@ public function toArray() ); } + /** + * @inheritDoc + */ + public function __serialize() + { + return $this->toArray(); + } + + /** + * @inheritDoc + */ + public function __unserialize($data) + { + $this->dependency1 = $data['dependency_1']; + $this->dependency2 = $data['dependency_2']; + $this->methodsCallCount = $data['method_call_count']; + } + /** * String representation of object *