‪TYPO3CMS  9.5
Mailer.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Swift_Transport;
21 
28 class ‪Mailer extends \Swift_Mailer
29 {
33  protected ‪$transport;
34 
38  protected ‪$mailSettings = [];
39 
46  public function ‪__construct(\Swift_Transport ‪$transport = null)
47  {
48  if (‪$transport !== null) {
49  $this->transport = ‪$transport;
50  } else {
51  if (empty($this->mailSettings)) {
52  $this->‪injectMailSettings();
53  }
54  try {
55  $this->‪initializeTransport();
56  } catch (\‪Exception $e) {
57  throw new \TYPO3\CMS\Core\Exception($e->getMessage(), 1291068569);
58  }
59  }
60  parent::__construct($this->transport);
61 
63  }
64 
82  private function ‪initializeTransport()
83  {
84  $this->transport = $this->‪getTransportFactory()->‪get($this->mailSettings);
85  }
86 
93  public function ‪injectMailSettings(array ‪$mailSettings = null)
94  {
95  if (is_array(‪$mailSettings)) {
96  $this->mailSettings = ‪$mailSettings;
97  } else {
98  $this->mailSettings = (array)‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'];
99  }
100  }
101 
107  public function ‪getRealTransport(): Swift_Transport
108  {
109  ‪$mailSettings = !empty($this->mailSettings) ? $this->mailSettings : (array)‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'];
110  unset(‪$mailSettings['transport_spool_type']);
112  }
113 
117  protected function ‪getTransportFactory(): ‪TransportFactory
118  {
119  return GeneralUtility::makeInstance(TransportFactory::class);
120  }
121 
127  protected function ‪getObjectManager()
128  {
129  return GeneralUtility::makeInstance(ObjectManager::class);
130  }
131 
137  protected function ‪getSignalSlotDispatcher()
138  {
139  return $this->‪getObjectManager()->‪get(Dispatcher::class);
140  }
141 
145  protected function ‪emitPostInitializeMailerSignal()
146  {
147  $this->‪getSignalSlotDispatcher()->‪dispatch('TYPO3\\CMS\\Core\\Mail\\Mailer', 'postInitializeMailer', [$this]);
148  }
149 }
‪TYPO3\CMS\Core\Mail\Mailer\$mailSettings
‪array $mailSettings
Definition: Mailer.php:36
‪TYPO3\CMS\Core\Mail\TransportFactory\get
‪Swift_Transport get(array $mailSettings)
Definition: TransportFactory.php:38
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Mail\Mailer\injectMailSettings
‪injectMailSettings(array $mailSettings=null)
Definition: Mailer.php:91
‪TYPO3\CMS\Core\Mail\Mailer\getRealTransport
‪Swift_Transport getRealTransport()
Definition: Mailer.php:105
‪TYPO3\CMS\Core\Mail\Mailer\emitPostInitializeMailerSignal
‪emitPostInitializeMailerSignal()
Definition: Mailer.php:143
‪TYPO3\CMS\Core\Mail\Mailer\getTransportFactory
‪TransportFactory getTransportFactory()
Definition: Mailer.php:115
‪TYPO3\CMS\Core\Mail\Mailer\$transport
‪Swift_Transport $transport
Definition: Mailer.php:32
‪TYPO3\CMS\Core\Mail\Mailer\initializeTransport
‪initializeTransport()
Definition: Mailer.php:80
‪TYPO3\CMS\Core\Mail\Mailer\getSignalSlotDispatcher
‪TYPO3 CMS Extbase SignalSlot Dispatcher getSignalSlotDispatcher()
Definition: Mailer.php:135
‪TYPO3\CMS\Extbase\SignalSlot\Dispatcher\dispatch
‪mixed dispatch($signalClassName, $signalName, array $signalArguments=[])
Definition: Dispatcher.php:115
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:29
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Mail\Mailer\getObjectManager
‪TYPO3 CMS Extbase Object ObjectManager getObjectManager()
Definition: Mailer.php:125
‪TYPO3\CMS\Extbase\Object\ObjectManager\get
‪object &T get($objectName,... $constructorArguments)
Definition: ObjectManager.php:94
‪TYPO3\CMS\Core\Mail\Mailer\__construct
‪__construct(\Swift_Transport $transport=null)
Definition: Mailer.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Mail
Definition: Mailer.php:2
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Core\Mail\TransportFactory
Definition: TransportFactory.php:26
‪TYPO3\CMS\Extbase\SignalSlot\Dispatcher
Definition: Dispatcher.php:28