Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
extensions: swoole
coverage: pcov
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr
Expand Down
8 changes: 5 additions & 3 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"additional_composer_arguments": [
"--no-scripts",
"--no-plugins"
"--no-scripts"
],
"extensions": [
"redis"
],
"ignore_php_platform_requirements": {
}
}
}
8 changes: 4 additions & 4 deletions .laminas-ci/pre-run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
JOB=$3
PHP_VERSION=$(echo "${JOB}" | jq -r '.php')

# Due to the fact that we are disabling plugins when installing/updating/downgrading composer dependencies
# we have to manually enable the coding standard here.
composer enable-codestandard
apt update
apt install -y "php${PHP_VERSION}-swoole"
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
},
"autoload-dev": {
"psr-4": {
"DotTest\\Mail\\": "test/"
"QueueTest\\App\\": "test/App/",
"QueueTest\\Swoole\\": "test/Swoole/"
}
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion config/autoload/log.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ return [
'writers' => [
'FileWriter' => [
'name' => 'stream',
'level' => \Dot\Log\Logger::ALERT, // this is equal to 1
'priority' => \Dot\Log\Logger::ALERT, // this is equal to 1
'options' => [
'stream' => __DIR__ . '/../../log/queue-log.log',
'formatter' => [
Expand Down
86 changes: 86 additions & 0 deletions config/autoload/mail.global.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

return [
/**
* Dotkernel mail module configuration
* Note that many of these options can be set programmatically too, when sending mail messages actually that is
* what you'll usually do, these configs provide just defaults and options that remain the same for all mails
*/
'dot_mail' => [
//the key is the mail service name, this is the default one, which does not extend any configuration
'default' => [
//message configuration
'message_options' => [
//from email address of the email
'from' => '',
//from name to be displayed instead of from address
'from_name' => '',
//reply-to email address of the email
'reply_to' => '',
//replyTo name to be displayed instead of the address
'reply_to_name' => '',
//destination email address as string or a list of email addresses
'to' => [],
//copy destination addresses
'cc' => [],
//hidden copy destination addresses
'bcc' => [],
//email subject
'subject' => '',
//body options - content can be plain text, HTML
'body' => [
'content' => '',
'charset' => 'utf-8',
],
//attachments config
'attachments' => [
'files' => [],
'dir' => [
'iterate' => false,
'path' => 'data/mail/attachments',
'recursive' => false,
],
],
],
/**
* the mail transport to use can be any class implementing
* Symfony\Component\Mailer\Transport\TransportInterface
*
* for standard mail transports, you can use these aliases:
* - sendmail => Symfony\Component\Mailer\Transport\SendmailTransport
* - esmtp => Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport
*
* defaults to sendmail
**/
'transport' => 'sendmail',
//options that will be used only if esmtp adapter is used
'smtp_options' => [
//hostname or IP address of the mail server
'host' => '',
//port of the mail server - 587 or 465 for secure connections
'port' => 587,
'connection_config' => [
//the smtp authentication identity
'username' => '',
//the smtp authentication credential
'password' => '',
/**
* tls will run by default on this component, use:
*
* null - to avoid interfering with automatic encryption
* false - to disable automatic encryption
*
* It's not recommended to disable TLS while connecting to an SMTP server over the Internet
**/
'tls' => null,
],
],
],
// option to log the SENT emails
'log' => [
'sent' => getcwd() . '/log/mail/sent.log',
],
],
];
10 changes: 5 additions & 5 deletions src/App/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Netglue\PsrContainer\Messenger\Container\Middleware\MessageHandlerMiddlewareStaticFactory;
use Netglue\PsrContainer\Messenger\Container\Middleware\MessageSenderMiddlewareStaticFactory;
use Netglue\PsrContainer\Messenger\HandlerLocator\OneToManyFqcnContainerHandlerLocator;
use Queue\App\Message\ExampleMessage;
use Queue\App\Message\ExampleMessageHandler;
use Queue\App\Message\Message;
use Queue\App\Message\MessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;

class ConfigProvider
Expand All @@ -37,7 +37,7 @@ private function getDependencies(): array
"message_bus_stamp_middleware" => [BusNameStampMiddlewareStaticFactory::class, "message_bus"],
"message_bus_sender_middleware" => [MessageSenderMiddlewareStaticFactory::class, "message_bus"],
"message_bus_handler_middleware" => [MessageHandlerMiddlewareStaticFactory::class, "message_bus"],
ExampleMessageHandler::class => AttributedServiceFactory::class,
MessageHandler::class => AttributedServiceFactory::class,
],
"aliases" => [
MessageBusInterface::class => "message_bus",
Expand Down Expand Up @@ -81,7 +81,7 @@ private function busConfig(): array
*/
'handler_locator' => OneToManyFqcnContainerHandlerLocator::class,
'handlers' => [
ExampleMessage::class => [ExampleMessageHandler::class],
Message::class => [MessageHandler::class],
],

/**
Expand All @@ -97,7 +97,7 @@ private function busConfig(): array
* Route specific messages to specific transports by using the message name as the key.
*/
'routes' => [
ExampleMessage::class => ["redis_transport"],
Message::class => ["redis_transport"],
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Queue\App\Message;

class ExampleMessage
class Message
{
public function __construct(
private array $payload,

Check notice on line 10 in src/App/Message/Message.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Property can be 'readonly'

Property can be 'readonly'

Check notice on line 10 in src/App/Message/Message.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Property can be 'readonly'

Property can be 'readonly'
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use function json_decode;

class ExampleMessageHandler
class MessageHandler
{
protected array $args = [];

Expand All @@ -35,18 +35,19 @@ public function __construct(
) {
}

public function __invoke(ExampleMessage $message): void
public function __invoke(Message $message): void
{
$payload = json_decode($message->getPayload()['foo'], true);

if ($payload !== null && isset($payload['userUuid'])) {
$this->logger->info("message: " . $payload['userUuid']);
$this->args = $payload;
}

try {
$this->perform();
} catch (Exception $exception) {
try {
$this->perform();
} catch (Exception $exception) {
$this->logger->err("message: " . $exception->getMessage());
}
}
}

Expand All @@ -64,7 +65,7 @@ public function perform(): void
public function sendWelcomeMail(): bool
{
$user = $this->userRepository->find($this->args['userUuid']);
$this->mailService->getMessage()->addTo('sergiubota@rospace.com', 'sergiu');
$this->mailService->getMessage()->addTo($user->getEmail(), $user->getName());
$this->mailService->setSubject('Welcome to ' . $this->config['application']['name']);
$body = $this->templateRenderer->render('notification-email::welcome', [
'user' => $user,
Expand Down
6 changes: 3 additions & 3 deletions src/Swoole/Delegators/TCPServerDelegator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Queue\Swoole\Delegators;

use Psr\Container\ContainerInterface;
use Queue\App\Message\ExampleMessage;
use Queue\App\Message\Message;
use Swoole\Server as TCPSwooleServer;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\DelayStamp;
Expand All @@ -28,8 +28,8 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal

// Register the function for the event `receive`
$server->on('receive', function ($server, $fd, $fromId, $data) use ($logger, $bus) {
$bus->dispatch(new ExampleMessage(["foo" => $data]));
$bus->dispatch(new ExampleMessage(["foo" => "with 5 seconds delay"]), [
$bus->dispatch(new Message(["foo" => $data]));
$bus->dispatch(new Message(["foo" => "with 5 seconds delay"]), [
new DelayStamp(5000),
]);

Expand Down
23 changes: 23 additions & 0 deletions test/App/AppConfigProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace QueueTest\App;

use PHPUnit\Framework\TestCase;
use Queue\App\ConfigProvider;

class AppConfigProviderTest extends TestCase
{
private array $config;

public function setUp(): void
{
$this->config = (new ConfigProvider())();
}

public function testHasDependencies(): void
{
$this->assertArrayHasKey('dependencies', $this->config);
}
}
Loading
Loading