[FEATURE] Add signal for mailer initialization
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Mail / Mailer.php
index a7ec245..1b38016 100644 (file)
@@ -17,6 +17,10 @@ namespace TYPO3\CMS\Core\Mail;
 // Make sure Swift's auto-loader is registered
 require_once PATH_typo3 . 'contrib/swiftmailer/lib/swift_required.php';
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
+
 /**
  * Adapter for Swift_Mailer to be used by TYPO3 extensions.
  *
@@ -57,6 +61,8 @@ class Mailer extends \Swift_Mailer {
                        }
                }
                parent::__construct($this->transport);
+
+               $this->emitPostInitializeMailerSignal();
        }
 
        /**
@@ -146,4 +152,30 @@ class Mailer extends \Swift_Mailer {
                }
        }
 
+       /**
+        * Get the object manager
+        *
+        * @return \TYPO3\CMS\Extbase\Object\ObjectManager
+        */
+       protected function getObjectManager() {
+               return GeneralUtility::makeInstance(ObjectManager::class);
+       }
+
+       /**
+        * Get the SignalSlot dispatcher
+        *
+        * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        */
+       protected function getSignalSlotDispatcher() {
+               return $this->getObjectManager()->get(Dispatcher::class);
+       }
+
+       /**
+        * Emits a signal after mailer initialization
+        *
+        * @return void
+        */
+       protected function emitPostInitializeMailerSignal() {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Mail\\Mailer', 'postInitializeMailer', array($this));
+       }
 }