mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 05:35:09 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c060e84476 | ||
|
|
bebac5992a | ||
|
|
7d15d85515 | ||
|
|
04719839ad | ||
|
|
1c057722bc |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
vendor/
|
||||
.phpunit.result.cache
|
||||
.php-cs-fixer.cache
|
||||
.php-cs-fixer.cache
|
||||
runtime/
|
||||
2
.idea/HDK-Core.iml
generated
2
.idea/HDK-Core.iml
generated
@@ -2,7 +2,6 @@
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="Singularity\HDK\Core\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Singularity\HDK\Test\Core\" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
|
||||
@@ -92,7 +91,6 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php81" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php72" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation-contracts" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/event-dispatcher" />
|
||||
|
||||
24
.idea/php-docker-settings.xml
generated
Normal file
24
.idea/php-docker-settings.xml
generated
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpDockerContainerSettings">
|
||||
<list>
|
||||
<map>
|
||||
<entry key="9fb85f67-19fd-423f-9358-1b155a12eb7d">
|
||||
<value>
|
||||
<DockerContainerSettings>
|
||||
<option name="version" value="1" />
|
||||
<option name="volumeBindings">
|
||||
<list>
|
||||
<DockerVolumeBindingImpl>
|
||||
<option name="containerPath" value="/opt/project" />
|
||||
<option name="hostPath" value="$PROJECT_DIR$" />
|
||||
</DockerVolumeBindingImpl>
|
||||
</list>
|
||||
</option>
|
||||
</DockerContainerSettings>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</list>
|
||||
</component>
|
||||
</project>
|
||||
14
.idea/php.xml
generated
14
.idea/php.xml
generated
@@ -107,7 +107,6 @@
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php81" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/translation" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher" />
|
||||
@@ -154,6 +153,19 @@
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/stopwatch" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpstan/phpstan" />
|
||||
<path value="$PROJECT_DIR$/vendor/doctrine/deprecations" />
|
||||
<path value="$PROJECT_DIR$/vendor/psr/clock" />
|
||||
<path value="$PROJECT_DIR$/vendor/hyperf/crontab" />
|
||||
<path value="$PROJECT_DIR$/vendor/fidry/cpu-core-counter" />
|
||||
<path value="$PROJECT_DIR$/vendor/carbonphp/carbon-doctrine-types" />
|
||||
<path value="$PROJECT_DIR$/vendor/cooper/hyperf-pest" />
|
||||
<path value="$PROJECT_DIR$/vendor/clue/ndjson-react" />
|
||||
<path value="$PROJECT_DIR$/vendor/evenement/evenement" />
|
||||
<path value="$PROJECT_DIR$/vendor/react/child-process" />
|
||||
<path value="$PROJECT_DIR$/vendor/react/cache" />
|
||||
<path value="$PROJECT_DIR$/vendor/react/dns" />
|
||||
<path value="$PROJECT_DIR$/vendor/react/stream" />
|
||||
<path value="$PROJECT_DIR$/vendor/react/event-loop" />
|
||||
<path value="$PROJECT_DIR$/vendor/react/socket" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
|
||||
|
||||
19
CHANGELOG.md
19
CHANGELOG.md
@@ -1,4 +1,23 @@
|
||||
# 版本更新日志
|
||||
### [0.1.9](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.8...v0.1.9) (2024-09-12)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **email:** 增加了单独定制发件人的方法 ([bebac59](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/bebac5992a89ebe41eb20ea926938f4b3fde2cc1))
|
||||
|
||||
### [0.1.8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.7...v0.1.8) (2024-09-12)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **email:** 增加了密送参数 ([1c05772](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/1c057722bcf407ab1faf6b5feb285e1e472fc627))
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **composer:** 更新依赖 ([0471983](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/04719839ad518ef3c00ffb67b8b563561de36858))
|
||||
|
||||
### [0.1.7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.6...v0.1.7) (2023-07-05)
|
||||
|
||||
|
||||
|
||||
@@ -114,5 +114,5 @@
|
||||
"url": "https://repo.huaweicloud.com/repository/php/"
|
||||
}
|
||||
},
|
||||
"version": "0.1.7"
|
||||
"version": "0.1.9"
|
||||
}
|
||||
|
||||
2587
composer.lock
generated
2587
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace Singularity\HDK\Core\Events;
|
||||
|
||||
use Singularity\HDK\Core\Service\EmailService;
|
||||
|
||||
/**
|
||||
* Singularity\HDK\Core\Events\EmailWillSent@HDK-Core
|
||||
*
|
||||
@@ -41,11 +43,21 @@ class EmailWillSent
|
||||
*/
|
||||
public array $cc = [];
|
||||
|
||||
/**
|
||||
* @var string[] $bcc
|
||||
*/
|
||||
public array $bcc = [];
|
||||
|
||||
/**
|
||||
* @var string 'text'|'html' $type
|
||||
*/
|
||||
public string $type = 'text';
|
||||
|
||||
/**
|
||||
* @var EmailService|null
|
||||
*/
|
||||
public ?EmailService $sender;
|
||||
|
||||
|
||||
public function __construct(
|
||||
/**
|
||||
@@ -58,12 +70,16 @@ class EmailWillSent
|
||||
* @var non-empty-string[] $cc
|
||||
*/
|
||||
array $cc = [],
|
||||
string $type = 'text'
|
||||
string $type = 'text',
|
||||
array $bcc = [],
|
||||
?EmailService $sender = null
|
||||
) {
|
||||
$this->type = $type;
|
||||
$this->cc = $cc;
|
||||
$this->content = $content;
|
||||
$this->subject = $subject;
|
||||
$this->target = $target;
|
||||
$this->bcc = $bcc;
|
||||
$this->sender = $sender;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,7 @@
|
||||
|
||||
namespace Singularity\HDK\Core\Listener;
|
||||
|
||||
use Hyperf\Contract\ContainerInterface;
|
||||
use Hyperf\Contract\StdoutLoggerInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\Event\Contract\ListenerInterface;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Singularity\HDK\Core\Constants\CommonErrorCode;
|
||||
@@ -43,7 +39,8 @@ class EmailWillSentListener extends AbstractListener
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailWillSent $event
|
||||
* @param object $event
|
||||
*
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -51,20 +48,24 @@ class EmailWillSentListener extends AbstractListener
|
||||
public function process(object $event): void
|
||||
{
|
||||
$stdoutLogger = $this->container->get(StdoutLoggerInterface::class);
|
||||
$emailService = $this->container->get(EmailService::class);
|
||||
|
||||
/** @var $event EmailWillSent */
|
||||
$emailService = $event->sender ?? EmailService::make();
|
||||
try {
|
||||
$event->type === 'html'
|
||||
? $emailService->sendHtml(
|
||||
$event->target,
|
||||
$event->subject,
|
||||
$event->content,
|
||||
$event->cc
|
||||
$event->cc,
|
||||
$event->bcc,
|
||||
)
|
||||
: $emailService->sendText(
|
||||
$event->target,
|
||||
$event->subject,
|
||||
$event->content,
|
||||
$event->cc
|
||||
$event->cc,
|
||||
$event->bcc,
|
||||
);
|
||||
|
||||
$stdoutLogger->info('邮件发送成功!');
|
||||
|
||||
@@ -42,6 +42,18 @@ class EmailService
|
||||
);
|
||||
}
|
||||
|
||||
public static function make(
|
||||
?string $dsn = null,
|
||||
?string $mailSenderName = null,
|
||||
?string $mailSender = null
|
||||
): EmailService {
|
||||
return new static(
|
||||
$dsn,
|
||||
$mailSenderName,
|
||||
$mailSender,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
@@ -66,9 +78,10 @@ class EmailService
|
||||
|
||||
/**
|
||||
* @param string|array<string> $target
|
||||
* @param string $subject
|
||||
* @param string $text
|
||||
* @param string $subject
|
||||
* @param string $text
|
||||
* @param array<string> $cc
|
||||
* @param array $bcc
|
||||
*
|
||||
* @return bool
|
||||
* @throws TransportExceptionInterface
|
||||
@@ -77,12 +90,14 @@ class EmailService
|
||||
$target,
|
||||
string $subject,
|
||||
string $text,
|
||||
array $cc = []
|
||||
array $cc = [],
|
||||
array $bcc = []
|
||||
): bool {
|
||||
$email = (new Email())
|
||||
->from(Address::create($this->from))
|
||||
->to(...(is_array($target) ? $target : [$target]))
|
||||
->cc(...$cc)
|
||||
->bcc(...$bcc)
|
||||
->subject($subject)
|
||||
->text($text);
|
||||
|
||||
@@ -95,9 +110,10 @@ class EmailService
|
||||
* 以 HTML 格式发送邮件
|
||||
*
|
||||
* @param string|array<string> $target
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param array<string> $cc
|
||||
* @param array $bcc
|
||||
*
|
||||
* @return bool
|
||||
* @throws TransportExceptionInterface
|
||||
@@ -106,12 +122,14 @@ class EmailService
|
||||
$target,
|
||||
string $subject,
|
||||
string $html,
|
||||
array $cc = []
|
||||
array $cc = [],
|
||||
array $bcc = []
|
||||
): bool {
|
||||
$email = (new Email())
|
||||
->from(Address::create($this->from))
|
||||
->to(...(is_array($target) ? $target : [$target]))
|
||||
->cc(...$cc)
|
||||
->bcc(...$bcc)
|
||||
->subject($subject)
|
||||
->html($html);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user