diff --git a/CRM/Core/Payment/OmnipayMultiProcessor.php b/CRM/Core/Payment/OmnipayMultiProcessor.php index 2b933e70e..7d55c2826 100644 --- a/CRM/Core/Payment/OmnipayMultiProcessor.php +++ b/CRM/Core/Payment/OmnipayMultiProcessor.php @@ -82,7 +82,18 @@ class CRM_Core_Payment_OmnipayMultiProcessor extends CRM_Core_Payment_PaymentExt * @var \Civi\Payment\PropertyBag */ protected $propertyBag; - + + /** + * For PHP8.1 + * https://www.php.net/manual/en/language.oop5.magic.php#object.serialize + * @return array + */ + public function __serialize(): array { + $data = (object) get_object_vars($this); + $this->cleanupObjectForSerialization($data, TRUE); + return (array) $data; + } + /** * Serialize, first removing gateway * @@ -91,8 +102,7 @@ class CRM_Core_Payment_OmnipayMultiProcessor extends CRM_Core_Payment_PaymentExt * @return string */ public function serialize(): string { - $this->cleanupClassForSerialization(TRUE); - return serialize(get_object_vars($this)); + return serialize($this->serialize()); } /** @@ -104,7 +114,17 @@ public function serialize(): string { */ public function unserialize($data) { $values = unserialize($data); - foreach ($values as $key => $value) { + $this->__unserialize($values); + } + + /** + * For PHP8.1 + * https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize + * + * @param array $data + */ + public function __unserialize(array $data): void { + foreach ($data as $key => $value) { $this->$key = $value; } } diff --git a/CRM/Core/Payment/PaymentExtended.php b/CRM/Core/Payment/PaymentExtended.php index 0093023cc..2872655a4 100644 --- a/CRM/Core/Payment/PaymentExtended.php +++ b/CRM/Core/Payment/PaymentExtended.php @@ -381,6 +381,25 @@ public function serialize() { return serialize($this); } + /** + * Unset various objects that will fail to serialize when the form is stored to session. + * + * @param object $object (by reference) + * @param bool $isIncludeGateWay Should we also unset the gateway. + */ + protected function cleanupObjectForSerialization(&$object, $isIncludeGateWay = FALSE) { + if (\Civi::settings()->get('omnipay_developer_mode') && !empty($object->history)) { + $object->logHttpTraffic(FALSE); + } + $object->history = []; + $object->client = NULL; + $object->lock = NULL; + $object->guzzleClient = NULL; + if ($isIncludeGateWay) { + $object->gateway = NULL; + } + } + /** * Unset various objects that will fail to serialize when the form is stored to session. * @@ -388,17 +407,9 @@ public function serialize() { * Should we also unset the gateway. * (possibly the default here should be TRUE but we want to be sure we are not * unsetting it when it is still being used.) + * For retro-compatibilty, this still transforms the current entity. */ protected function cleanupClassForSerialization($isIncludeGateWay = FALSE) { - if (\Civi::settings()->get('omnipay_developer_mode') && !empty($this->history)) { - $this->logHttpTraffic(FALSE); - } - $this->history = []; - $this->client = NULL; - $this->lock = NULL; - $this->guzzleClient = NULL; - if ($isIncludeGateWay) { - $this->gateway = NULL; - } + $this->cleanupObjectForSerialization($this, $isIncludeGateWay); } }