Version 1.0.0

This commit is contained in:
2025-12-12 11:41:44 +04:00
commit df7e485650
30 changed files with 7761 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace Diffhead\PHP\LaravelRabbitMQ\Service;
use Diffhead\PHP\LaravelRabbitMQ\Exception\AssociatedEventNotFound;
use Diffhead\PHP\LaravelRabbitMQ\Interface\EventMapper as EventMapperInterface;
use Diffhead\PHP\LaravelRabbitMQ\Object\Queue;
use App\Shared\Event\Event;
use Illuminate\Contracts\Foundation\Application;
class EventMapper implements EventMapperInterface
{
public function __construct(
private Application $app
) {}
public function map(Queue $queue, array $payload): Event
{
$map = config('rabbitmq.event.map', []);
$queueName = $queue->name();
$routingKey = $queue->bindings()->routingKey();
foreach ($map as $eventClass => $config) {
$match = null;
if (! empty($config['queues'] ?? [])) {
$match = in_array($queueName, $config['queues'], true);
}
if (! empty($config['routing_keys'] ?? [])) {
$match = is_null($match) ? true : $match;
$match = $match && in_array($routingKey, $config['routing_keys'], true);
}
if (is_null($match)) {
return $this->app->make($eventClass, $payload);
}
if (is_bool($match) && $match) {
return $this->app->make($eventClass, $payload);
}
}
throw new AssociatedEventNotFound(json_encode($payload));
}
}