From cb73ba87e07835b491e0cf3a34580ca81347ef94 Mon Sep 17 00:00:00 2001 From: Alexander Kras'ko <0m3r.mail@gmail.com> Date: Thu, 22 Apr 2021 15:55:22 +0300 Subject: [PATCH] add 2.3 backward compatibility --- Mail/EmailMessage.php | 38 ++++++++++++++++++++++++++++++++-- Mail/EmailMessageInterface.php | 5 ++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Mail/EmailMessage.php b/Mail/EmailMessage.php index 6e42539..0971f37 100644 --- a/Mail/EmailMessage.php +++ b/Mail/EmailMessage.php @@ -19,8 +19,42 @@ class EmailMessage extends FrameworkEmailMessage implements EmailMessageInterfac /** * @return Message */ - public function getZendMessage(): Message + public function getZendMessage() { - return $this->zendMessage; + if (property_exists($this, 'zendMessage')) { + return $this->zendMessage; + } + // 2.3 backward compatibility + try { + $message = $this->getPrivateParentPropertyValue('zendMessage'); + return $message; + } catch (\ReflectionException $e) { + } + if (property_exists($this, 'message')) { + return $this->message; + } + try { + $message = $this->getPrivateParentPropertyValue('message'); + return $message; + } catch (\ReflectionException $e) { + } + + throw new \Exception('The "zendMessage" property should exist in instance of EmailMessage'); + } + + /** + * @param string $propertyName + * @return mixed + * @throws \ReflectionException + */ + private function getPrivateParentPropertyValue($propertyName) + { + $reflectionClass = new \ReflectionClass($this); + $parentReflectionClass = $reflectionClass->getParentClass(); + $property = $parentReflectionClass->getProperty((string) $propertyName); + $property->setAccessible(true); + $value = $property->getValue($this); + + return $value; } } diff --git a/Mail/EmailMessageInterface.php b/Mail/EmailMessageInterface.php index 4669bfc..89f5696 100644 --- a/Mail/EmailMessageInterface.php +++ b/Mail/EmailMessageInterface.php @@ -11,5 +11,8 @@ */ interface EmailMessageInterface extends FrameworkEmailMessageInterface { - public function getZendMessage(): Message; + /** + * @return Message + */ + public function getZendMessage(); }