Skip to content

Commit 2274bab

Browse files
authored
Merge pull request #1 from PhantPHP/Version-2
Version 2
2 parents 05bb904 + 7e9c7f3 commit 2274bab

7 files changed

+129
-118
lines changed

.php-cs-fixer.cache

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"8.1.2","version":"3.12.0:v3.12.0#eae11d945e2885d86e1c080eec1bb30a2aa27998","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true},"hashes":{"test\/Service\/EmailAddressValidatorTest.php":1425368365,"component\/Service\/SendinblueEmailSender.php":3356570851,"component\/Service\/EmailAddressValidator.php":2293937196,"component\/Port\/EmailSender.php":2513942973}}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Requirments
44

5-
PHP >= 8.0
5+
PHP >= 8.1
66

77

88
## Install

component/Port/EmailSender.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Phant\EmailSender\Port;
6+
57
use Phant\DataStructure\Web\Email;
68

79
interface EmailSender
810
{
9-
public function send(Email $email): bool;
11+
public function send(Email $email): bool;
1012
}
+31-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Phant\EmailSender\Service;
56

67
use Phant\DataStructure\Web\EmailAddress;
78
use Phant\DomainName\Service\{
8-
DnsRecord,
9-
ServiceProvided,
9+
DnsRecord,
10+
ServiceProvided,
1011
};
1112
use Phant\EmailAddress\Error\EmailAddress\{
12-
IsTrashMailBoxService,
13-
EmailServerNotFound,
13+
IsTrashMailBoxService,
14+
EmailServerNotFound,
1415
};
1516

1617
class EmailAddressValidator
1718
{
18-
public function __construct()
19-
{
20-
}
21-
22-
public function checkTrashMailBoxService(string|EmailAddress $emailAddress): bool
23-
{
24-
if (is_string($emailAddress)) $emailAddress = new EmailAddress($emailAddress);
25-
26-
return (new ServiceProvided())->isTrashMailBoxService(
27-
$emailAddress->getDomainName()
28-
);
29-
}
30-
31-
public function checkMxServer(string|EmailAddress $emailAddress): bool
32-
{
33-
if (is_string($emailAddress)) $emailAddress = new EmailAddress($emailAddress);
34-
35-
return (new DnsRecord())->exist(
36-
$emailAddress->getDomainName(),
37-
DnsRecord::MX
38-
);
39-
}
19+
public function __construct()
20+
{
21+
}
22+
23+
public function checkTrashMailBoxService(string|EmailAddress $emailAddress): bool
24+
{
25+
if (is_string($emailAddress)) {
26+
$emailAddress = new EmailAddress($emailAddress);
27+
}
28+
29+
return (new ServiceProvided())->isTrashMailBoxService(
30+
$emailAddress->getDomainName()
31+
);
32+
}
33+
34+
public function checkMxServer(string|EmailAddress $emailAddress): bool
35+
{
36+
if (is_string($emailAddress)) {
37+
$emailAddress = new EmailAddress($emailAddress);
38+
}
39+
40+
return (new DnsRecord())->exist(
41+
$emailAddress->getDomainName(),
42+
DnsRecord::MX
43+
);
44+
}
4045
}
+54-55
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Phant\EmailSender\Service;
@@ -14,59 +15,57 @@
1415

1516
final class SendinblueEmailSender implements \Phant\EmailSender\Port\EmailSender
1617
{
17-
protected string $apiKey;
18-
19-
public function __construct(string $apiKey)
20-
{
21-
$this->apiKey = $apiKey;
22-
}
23-
24-
public function send(Email $email): bool
25-
{
26-
$headers = [
27-
'api-key' => $this->apiKey,
28-
'Accept' => 'application/json',
29-
'Content-Type' => 'application/json',
30-
];
31-
32-
$body = [
33-
'sender' => [
34-
'email' => (string)$email->from->getEmailAddress(),
35-
'name' => $email->from->getName(),
36-
],
37-
'to' => [
38-
[
39-
'email' => (string)$email->to->getEmailAddress(),
40-
'name' => $email->to->getName(),
41-
],
42-
],
43-
'subject' => $email->subject,
44-
];
45-
46-
if ($email->messageTxt) {
47-
$body['textContent'] = $email->messageTxt;
48-
}
49-
50-
if ($email->messageHtml) {
51-
$body['htmlContent'] = $email->messageHtml;
52-
}
53-
54-
$response = (new HttpClient([
55-
'base_uri' => 'https://api.sendinblue.com'
56-
]))->request(
57-
'POST',
58-
'/v3/smtp/email',
59-
[
60-
'headers' => $headers,
61-
'json' => $body,
62-
'http_errors' => false,
63-
]
64-
);
65-
66-
if ($response->getStatusCode() != 201) {
67-
return false;
68-
}
69-
70-
return true;
71-
}
18+
public function __construct(
19+
protected readonly string $apiKey
20+
) {
21+
}
22+
23+
public function send(Email $email): bool
24+
{
25+
$headers = [
26+
'api-key' => $this->apiKey,
27+
'Accept' => 'application/json',
28+
'Content-Type' => 'application/json',
29+
];
30+
31+
$body = [
32+
'sender' => [
33+
'email' => (string)$email->from->getEmailAddress(),
34+
'name' => $email->from->getName(),
35+
],
36+
'to' => [
37+
[
38+
'email' => (string)$email->to->getEmailAddress(),
39+
'name' => $email->to->getName(),
40+
],
41+
],
42+
'subject' => $email->subject,
43+
];
44+
45+
if ($email->messageTxt) {
46+
$body['textContent'] = $email->messageTxt;
47+
}
48+
49+
if ($email->messageHtml) {
50+
$body['htmlContent'] = $email->messageHtml;
51+
}
52+
53+
$response = (new HttpClient([
54+
'base_uri' => 'https://api.sendinblue.com'
55+
]))->request(
56+
'POST',
57+
'/v3/smtp/email',
58+
[
59+
'headers' => $headers,
60+
'json' => $body,
61+
'http_errors' => false,
62+
]
63+
);
64+
65+
if ($response->getStatusCode() != 201) {
66+
return false;
67+
}
68+
69+
return true;
70+
}
7271
}

composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
],
1212
"require": {
1313
"php": "^8.0",
14-
"phant/data-structure": "3.*",
15-
"phant/domain-name": "1.*",
14+
"phant/data-structure": "4.*",
15+
"phant/domain-name": "2.*",
1616
"guzzlehttp/guzzle": "^7.4"
1717
},
1818
"require-dev": {
19+
"friendsofphp/php-cs-fixer": "^3.0",
1920
"phpstan/phpstan": "^1.4",
2021
"phpunit/phpunit": "^9.5"
2122
},
2223
"scripts": {
24+
"lint": "vendor/bin/php-cs-fixer fix ./ --rules=@PSR12",
2325
"analyse": "vendor/bin/phpstan analyse component --memory-limit=4G",
2426
"test": "vendor/bin/phpunit test --testdox"
2527
},
+35-33
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Test\Service;
6+
57
use PHPUnit\Framework\TestCase;
68

79
use Phant\DataStructure\Web\EmailAddress;
810
use Phant\EmailSender\Service\EmailAddressValidator;
911

1012
final class EmailAddressValidatorTest extends TestCase
1113
{
12-
public function testCheckTrashMailBoxService(): void
13-
{
14-
$this->assertIsBool(
15-
(new EmailAddressValidator())
16-
->checkTrashMailBoxService(
17-
18-
)
19-
);
20-
21-
$this->assertIsBool(
22-
(new EmailAddressValidator())
23-
->checkTrashMailBoxService(
24-
new EmailAddress('[email protected]')
25-
)
26-
);
27-
}
28-
29-
public function testCheckMxServer(): void
30-
{
31-
$this->assertIsBool(
32-
(new EmailAddressValidator())
33-
->checkMxServer(
34-
35-
)
36-
);
37-
38-
$this->assertIsBool(
39-
(new EmailAddressValidator())
40-
->checkMxServer(
41-
new EmailAddress('[email protected]')
42-
)
43-
);
44-
}
14+
public function testCheckTrashMailBoxService(): void
15+
{
16+
$this->assertIsBool(
17+
(new EmailAddressValidator())
18+
->checkTrashMailBoxService(
19+
20+
)
21+
);
22+
23+
$this->assertIsBool(
24+
(new EmailAddressValidator())
25+
->checkTrashMailBoxService(
26+
new EmailAddress('[email protected]')
27+
)
28+
);
29+
}
30+
31+
public function testCheckMxServer(): void
32+
{
33+
$this->assertIsBool(
34+
(new EmailAddressValidator())
35+
->checkMxServer(
36+
37+
)
38+
);
39+
40+
$this->assertIsBool(
41+
(new EmailAddressValidator())
42+
->checkMxServer(
43+
new EmailAddress('[email protected]')
44+
)
45+
);
46+
}
4547
}

0 commit comments

Comments
 (0)