PageRenderTime 127ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/laravel/framework/src/Illuminate/Mail/TransportManager.php

https://gitlab.com/alamgircsejnu/AMS-Project-Laravel
PHP | 186 lines | 96 code | 27 blank | 63 comment | 5 complexity | 7f8b01378bb02ed8c140912fda03044c MD5 | raw file
  1. <?php
  2. namespace Illuminate\Mail;
  3. use Aws\Ses\SesClient;
  4. use Illuminate\Support\Arr;
  5. use Illuminate\Support\Manager;
  6. use GuzzleHttp\Client as HttpClient;
  7. use Swift_SmtpTransport as SmtpTransport;
  8. use Swift_MailTransport as MailTransport;
  9. use Illuminate\Mail\Transport\LogTransport;
  10. use Illuminate\Mail\Transport\SesTransport;
  11. use Illuminate\Mail\Transport\MailgunTransport;
  12. use Illuminate\Mail\Transport\MandrillTransport;
  13. use Illuminate\Mail\Transport\SparkPostTransport;
  14. use Swift_SendmailTransport as SendmailTransport;
  15. class TransportManager extends Manager
  16. {
  17. /**
  18. * Create an instance of the SMTP Swift Transport driver.
  19. *
  20. * @return \Swift_SmtpTransport
  21. */
  22. protected function createSmtpDriver()
  23. {
  24. $config = $this->app['config']['mail'];
  25. // The Swift SMTP transport instance will allow us to use any SMTP backend
  26. // for delivering mail such as Sendgrid, Amazon SES, or a custom server
  27. // a developer has available. We will just pass this configured host.
  28. $transport = SmtpTransport::newInstance(
  29. $config['host'], $config['port']
  30. );
  31. if (isset($config['encryption'])) {
  32. $transport->setEncryption($config['encryption']);
  33. }
  34. // Once we have the transport we will check for the presence of a username
  35. // and password. If we have it we will set the credentials on the Swift
  36. // transporter instance so that we'll properly authenticate delivery.
  37. if (isset($config['username'])) {
  38. $transport->setUsername($config['username']);
  39. $transport->setPassword($config['password']);
  40. }
  41. if (isset($config['stream'])) {
  42. $transport->setStreamOptions($config['stream']);
  43. }
  44. return $transport;
  45. }
  46. /**
  47. * Create an instance of the Sendmail Swift Transport driver.
  48. *
  49. * @return \Swift_SendmailTransport
  50. */
  51. protected function createSendmailDriver()
  52. {
  53. $command = $this->app['config']['mail']['sendmail'];
  54. return SendmailTransport::newInstance($command);
  55. }
  56. /**
  57. * Create an instance of the Amazon SES Swift Transport driver.
  58. *
  59. * @return \Swift_SendmailTransport
  60. */
  61. protected function createSesDriver()
  62. {
  63. $config = $this->app['config']->get('services.ses', []);
  64. $config += [
  65. 'version' => 'latest', 'service' => 'email',
  66. ];
  67. if ($config['key'] && $config['secret']) {
  68. $config['credentials'] = Arr::only($config, ['key', 'secret']);
  69. }
  70. return new SesTransport(new SesClient($config));
  71. }
  72. /**
  73. * Create an instance of the Mail Swift Transport driver.
  74. *
  75. * @return \Swift_MailTransport
  76. */
  77. protected function createMailDriver()
  78. {
  79. return MailTransport::newInstance();
  80. }
  81. /**
  82. * Create an instance of the Mailgun Swift Transport driver.
  83. *
  84. * @return \Illuminate\Mail\Transport\MailgunTransport
  85. */
  86. protected function createMailgunDriver()
  87. {
  88. $config = $this->app['config']->get('services.mailgun', []);
  89. return new MailgunTransport(
  90. $this->getHttpClient($config),
  91. $config['secret'], $config['domain']
  92. );
  93. }
  94. /**
  95. * Create an instance of the Mandrill Swift Transport driver.
  96. *
  97. * @return \Illuminate\Mail\Transport\MandrillTransport
  98. */
  99. protected function createMandrillDriver()
  100. {
  101. $config = $this->app['config']->get('services.mandrill', []);
  102. return new MandrillTransport(
  103. $this->getHttpClient($config), $config['secret']
  104. );
  105. }
  106. /**
  107. * Create an instance of the SparkPost Swift Transport driver.
  108. *
  109. * @return \Illuminate\Mail\Transport\SparkPostTransport
  110. */
  111. protected function createSparkPostDriver()
  112. {
  113. $config = $this->app['config']->get('services.sparkpost', []);
  114. return new SparkPostTransport(
  115. $this->getHttpClient($config),
  116. $config['secret'],
  117. Arr::get($config, 'options', [])
  118. );
  119. }
  120. /**
  121. * Create an instance of the Log Swift Transport driver.
  122. *
  123. * @return \Illuminate\Mail\Transport\LogTransport
  124. */
  125. protected function createLogDriver()
  126. {
  127. return new LogTransport($this->app->make('Psr\Log\LoggerInterface'));
  128. }
  129. /**
  130. * Get a fresh Guzzle HTTP client instance.
  131. *
  132. * @param array $config
  133. * @return HttpClient
  134. */
  135. protected function getHttpClient($config)
  136. {
  137. $guzzleConfig = Arr::get($config, 'guzzle', []);
  138. return new HttpClient(Arr::add($guzzleConfig, 'connect_timeout', 60));
  139. }
  140. /**
  141. * Get the default mail driver name.
  142. *
  143. * @return string
  144. */
  145. public function getDefaultDriver()
  146. {
  147. return $this->app['config']['mail.driver'];
  148. }
  149. /**
  150. * Set the default mail driver name.
  151. *
  152. * @param string $name
  153. * @return void
  154. */
  155. public function setDefaultDriver($name)
  156. {
  157. $this->app['config']['mail.driver'] = $name;
  158. }
  159. }