-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.php
More file actions
52 lines (46 loc) · 1.68 KB
/
base.php
File metadata and controls
52 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
abstract class baseCmd
{
function setDB()
{
$dbConfig = require APP_PATH . '/config/db.php';
$capsule = new DB;
$capsule->addConnection($dbConfig);
// $configIasset = $dbConfigAll['iasset'];
// $capsule->addConnection($configIasset, 'iasset');
$capsule->setEventDispatcher(new Dispatcher(new Container));
$capsule->setAsGlobal();
$capsule->bootEloquent();
DB::connection()->enableQueryLog(); // 开启调试
}
function phpmailer($user, $subject, $content, $file = '')
{
$mailConfig = include APP_PATH . '/config/mail.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = false;
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = $mailConfig['host'];
$mail->Username = $mailConfig['username'];
$mail->Password = $mailConfig['password'];
$mail->Port = $mailConfig['port'];
$mail->CharSet = "utf-8";
$mail->SMTPDebug = 2;
$mail->Debugoutput = function ($str, $level) {
if (preg_match('/CLIENT\s->\sSERVER:\s.{76}/i', $str)) return;
file_put_contents(APP_PATH . '/cache/log/smtp.log', date('Y-m-d H:i:s'). "\t$level\t$str\n", FILE_APPEND | LOCK_EX);
};
$mail->setFrom($mailConfig['username'], $mailConfig['username']);
return $mail;
}
function log()
{
$logFile = APP_PATH . "/cache/log/{$GLOBALS['argv'][1]}.log";
writeFileLog($logFile, func_get_args());
}
}