Completed
Pull Request — master (#35)
by
unknown
02:56
created

QueueTransport::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 1
dl 0
loc 23
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Mark Scherer
4
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
5
 */
6
namespace Queue\Mailer\Transport;
7
8
use Cake\Mailer\AbstractTransport;
9
use Cake\Mailer\Email;
10
use Cake\ORM\TableRegistry;
11
12
/**
13
 * Send mail using Queue plugin
14
 */
15
class QueueTransport extends AbstractTransport
16
{
17
18
    /**
19
     * Send mail
20
     *
21
     * @param \Cake\Mailer\Email $email Email
22
     * @return array
23
     */
24
    public function send(Email $email)
25
    {
26
        if (!empty($this->_config['queue'])) {
27
            $this->_config = $this->_config['queue'] + $this->_config;
28
            $email->setConfig((array)$this->_config['queue'] + [
29
                'queue' => []
30
            ]);
31
            unset($this->_config['queue']);
32
        }
33
34
        $transport = $this->_config['transport'];
35
        $email->setTransport($transport);
36
37
        /** @var \Queue\Model\Table\QueuedTasksTable $QueuedTasks */
38
        $QueuedTasks = TableRegistry::getTableLocator()->get('Queue.QueuedTasks');
39
        $result = $QueuedTasks->createJob('Email', [
40
            'transport' => $transport,
41
            'settings' => $email
42
        ]);
43
        $result['headers'] = '';
44
        $result['message'] = '';
45
46
        return $result->toArray();
47
    }
48
}
49