Completed
Push — master ( 7fe22c...328c86 )
by Stefano
02:25
created

Email::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 2
eloc 14
nc 2
nop 1
1
<?php
2
3
/**
4
 * Email
5
 *
6
 * Send messages via Email services.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2016 - http://caffeina.com
11
 */
12
13
class Email {
14
  use Module;
15
16
  protected static $driver,
17
                   $options,
18
                   $driver_name;
19
20
  public static function using($driver, $options = null){
21
    $class = 'Email\\'.ucfirst(strtolower($driver));
22
    if ( ! class_exists($class) ) throw new \Exception("[core.email] : $driver driver not found.");
23
    static::$driver_name = $driver;
24
    static::$options     = $options;
25
    static::$driver      = new $class;
26
    static::$driver->onInit($options);
27
  }
28
29
  public static function create($mail=[]){
30
    if (is_a($mail, 'Email\\Envelope')){
31
      return $mail;
32
    } else {
33
      return new Email\Envelope(array_merge([
34
        'to'          => false,
35
        'from'        => false,
36
        'cc'          => false,
37
        'bcc'         => false,
38
        'replyTo'     => false,
39
        'subject'     => false,
40
        'message'     => false,
41
        'attachments' => [],
42
      ], $mail));
43
    }    
44
  }
45
46
  public static function send($mail){
47
    return static::$driver->onSend(static::create($mail));
48
  }
49
50
}
51
52
Email::using('native');
53