Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
<?php
|
|
2 |
/**
|
|
3 |
* This file is part of the Shieldon package.
|
|
4 |
*
|
|
5 |
* (c) Terry L. <contact@terryl.in>
|
|
6 |
*
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
8 |
* file that was distributed with this source code.
|
|
9 |
*
|
|
10 |
* php version 7.1.0
|
|
11 |
*
|
|
12 |
* @category Web-security
|
|
13 |
* @package Shieldon
|
|
14 |
* @author Terry Lin <contact@terryl.in>
|
|
15 |
* @copyright 2019 terrylinooo
|
|
16 |
* @license https://github.com/terrylinooo/shieldon/blob/2.x/LICENSE MIT
|
|
17 |
* @link https://github.com/terrylinooo/shieldon
|
|
18 |
* @see https://shieldon.io
|
|
19 |
*/
|
|
20 |
|
|
21 |
declare(strict_types=1); |
|
22 |
|
|
23 |
namespace Shieldon\Firewall\Panel\Sandbox; |
|
24 |
|
|
25 |
use Shieldon\Messenger\Sendgrid as SendgridTest; |
|
26 |
use function explode; |
|
27 |
use function filter_var; |
|
28 |
use function str_replace; |
|
29 |
|
|
30 |
/**
|
|
31 |
* The sandbox for Sendgrid.
|
|
32 |
*/
|
|
33 |
class Sendgrid |
|
34 |
{
|
|
35 |
/**
|
|
36 |
* Invoker.
|
|
37 |
*
|
|
38 |
* @param array $args The arguments.
|
|
39 |
*
|
|
40 |
* @return bool
|
|
41 |
*/
|
|
42 | 3 |
public function __invoke(array $args): bool |
43 |
{
|
|
44 | 3 |
return $this->sandbox($args[0], $args[1]); |
45 |
}
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Test Sendgrid.
|
|
49 |
*
|
|
50 |
* @param array $getParams The GET params passed from tryMessenger method.
|
|
51 |
* @param array $message The message title and body.
|
|
52 |
*
|
|
53 |
* @return bool
|
|
54 |
*/
|
|
55 | 3 |
private function sandbox($getParams, $message) |
56 |
{
|
|
57 | 3 |
$apiKey = $getParams['apiKey'] ?? ''; |
58 | 3 |
$sender = $getParams['sender'] ?? ''; |
59 | 3 |
$recipients = $getParams['recipients'] ?? ''; |
60 |
|
|
61 | 3 |
if (!empty($sender) && !empty($recipients) && !empty($apiKey)) { |
62 | 3 |
$recipients = str_replace("\r", '|', $recipients); |
63 | 3 |
$recipients = str_replace("\n", '|', $recipients); |
64 | 3 |
$recipients = explode('|', $recipients); |
65 |
|
|
66 | 3 |
$messenger = new SendgridTest($apiKey); |
67 |
|
|
68 | 3 |
foreach ($recipients as $recipient) { |
69 | 3 |
if (filter_var($recipient, FILTER_VALIDATE_EMAIL)) { |
70 | 3 |
$messenger->addRecipient($recipient); |
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 | 3 |
if (filter_var($sender, FILTER_VALIDATE_EMAIL)) { |
75 | 3 |
$messenger->addSender($sender); |
76 |
}
|
|
77 |
|
|
78 | 3 |
$messenger->setSubject($message['title']); |
79 |
|
|
80 | 3 |
if ($messenger->send($message['body'])) { |
81 |
// @codeCoverageIgnoreStart
|
|
82 |
return true; |
|
83 |
// @codeCoverageIgnoreEnd
|
|
84 |
}
|
|
85 |
}
|
|
86 | 3 |
return false; |
87 |
}
|
|
88 |
}
|
Read our documentation on viewing source code .