Passed
Push — master ( 662d52...2a8232 )
by eXeCUT
03:58
created

models/FilesSource.php (18 issues)

1
<?php
2
3
namespace execut\import\models;
4
5
use execut\import\components\source\adapter\Email;
6
use execut\import\components\source\adapter\email\Filter;
7
use execut\import\components\source\adapter\email\Receiver;
8
use execut\import\components\source\adapter\Ftp;
9
use execut\import\components\source\adapter\Site;
10
use execut\yii\base\Exception;
11
use Yii;
12
use yii\helpers\ArrayHelper;
13
14
/**
15
 * This is the model class for table "import_files_sources".
16
 *
17
 * @property integer $id
18
 * @property string $created
19
 * @property string $updated
20
 * @property string $name
21
 * @property string $key
22
 *
23
 * @property \execut\import\models\File[] $importFiles
24
 */
25
class FilesSource extends base\FilesSource
26
{
27
    public static $emailAdapter = null;
28
//    const ALL_TYPES = [
29
//        self::TYPE_EMAIL,
30
//        self::TYPE_FTP,
31
//        self::TYPE_SITE,
32
//    ];
33
    const TYPE_EMAIL = 'email';
34
    const TYPE_FTP = 'ftp';
35
    const TYPE_SITE = 'site';
36
    public function getAdapterForSetting(Setting $setting) {
37
        switch ($this->key) {
38
            case self::TYPE_EMAIL:
39
                if (self::$emailAdapter === null) {
40
                    self::$emailAdapter = new Email([
41
                        'receiver' => new Receiver([
42
                            'imap' => \yii::$app->imap->connection,
43
                            'filter' => new Filter(),
44
                        ]),
45
                    ]);
46
                }
47
48
                $adapter = self::$emailAdapter;
49
                /**
50
                 * @var Filter $filter
51
                 */
52
                $filter = $adapter->receiver->filter;
53
                $filter->subject = $setting->email_title_match;
54
                $filter->attachmentName = $setting->email_attachment_template;
0 ignored issues
show
Bug Best Practice introduced by
The property email_attachment_template does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
                $filter->sender = $setting->email;
56
            break;
57
            case self::TYPE_FTP:
58
                $adapter = new Ftp([
59
                    'host' => $setting->ftp_host,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_host does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
60
                    'ssl' => $setting->ftp_ssl,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_ssl does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
61
                    'port' => $setting->ftp_port,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_port does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
62
                    'timeout' => $setting->ftp_timeout,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_timeout does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
63
                    'login' => $setting->ftp_login,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_login does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
64
                    'password' => $setting->ftp_password,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_password does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
65
                    'dir' => $setting->ftp_dir,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_dir does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
66
                    'fileName' => $setting->ftp_file_name,
0 ignored issues
show
Bug Best Practice introduced by
The property ftp_file_name does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
67
                ]);
68
            break;
69
            case self::TYPE_SITE:
70
                $adapter = new Site([
71
                    'site' => $setting->site_host,
0 ignored issues
show
Bug Best Practice introduced by
The property site_host does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
72
                    'authUrl' => $setting->site_auth_url,
0 ignored issues
show
Bug Best Practice introduced by
The property site_auth_url does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
73
                    'method' => $setting->site_auth_method,
0 ignored issues
show
Bug Best Practice introduced by
The property site_auth_method does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
74
                    'loginField' => $setting->site_login_field,
0 ignored issues
show
Bug Best Practice introduced by
The property site_login_field does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
75
                    'passwordField' => $setting->site_password_field,
0 ignored issues
show
Bug Best Practice introduced by
The property site_password_field does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
76
                    'otherFields' => $setting->siteOtherFields,
0 ignored issues
show
Bug Best Practice introduced by
The property siteOtherFields does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
77
                    'login' => $setting->site_login,
0 ignored issues
show
Bug Best Practice introduced by
The property site_login does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
78
                    'password' => $setting->site_password,
0 ignored issues
show
Bug Best Practice introduced by
The property site_password does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
79
                    'fileUrl' => $setting->site_file_url,
0 ignored issues
show
Bug Best Practice introduced by
The property site_file_url does not exist on execut\import\models\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
80
                ]);
81
            break;
82
            default:
83
                throw new Exception('Adapter for source type ' . $this->key . ' is not supported');
84
        }
85
86
        return $adapter;
87
    }
88
}
89