1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP(tm) Project
12: * @since 2.0.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15: namespace Cake\Mailer;
16:
17: use Cake\Core\InstanceConfigTrait;
18:
19: /**
20: * Abstract transport for sending email
21: */
22: abstract class AbstractTransport
23: {
24: use InstanceConfigTrait;
25:
26: /**
27: * Default config for this class
28: *
29: * @var array
30: */
31: protected $_defaultConfig = [];
32:
33: /**
34: * Send mail
35: *
36: * @param \Cake\Mailer\Email $email Email instance.
37: * @return array
38: */
39: abstract public function send(Email $email);
40:
41: /**
42: * Constructor
43: *
44: * @param array $config Configuration options.
45: */
46: public function __construct($config = [])
47: {
48: $this->setConfig($config);
49: }
50:
51: /**
52: * Help to convert headers in string
53: *
54: * @param array $headers Headers in format key => value
55: * @param string $eol End of line string.
56: * @return string
57: */
58: protected function _headersToString($headers, $eol = "\r\n")
59: {
60: $out = '';
61: foreach ($headers as $key => $value) {
62: if ($value === false || $value === null || $value === '') {
63: continue;
64: }
65: $out .= $key . ': ' . $value . $eol;
66: }
67: if (!empty($out)) {
68: $out = substr($out, 0, -1 * strlen($eol));
69: }
70:
71: return $out;
72: }
73: }
74: