Skip to content

Commit

Permalink
Merge pull request #48 from akondas/fix-deprecation
Browse files Browse the repository at this point in the history
Inject service client instead of container - fix deprecation
  • Loading branch information
mnapoli authored Jun 8, 2021
2 parents df62881 + b0c1574 commit c790986
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
10 changes: 4 additions & 6 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ services:
# SNS
Bref\Symfony\Messenger\Service\Sns\SnsTransportFactory:
tags: ['messenger.transport_factory']
autowire: true
arguments:
- '@bref.messenger.sns_client'
bref.messenger.sns_client:
class: AsyncAws\Sns\SnsClient
public: true


# EventBridge
Bref\Symfony\Messenger\Service\EventBridge\EventBridgeTransportFactory:
tags: ['messenger.transport_factory']
autowire: true
arguments:
- '@bref.messenger.eventbridge_client'
bref.messenger.eventbridge_client:
class: AsyncAws\EventBridge\EventBridgeClient
public: true

4 changes: 2 additions & 2 deletions src/Service/EventBridge/EventBridgeTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class EventBridgeTransport implements TransportInterface
/** @var string */
private $source;

public function __construct(EventBridgeClient $sns, SerializerInterface $serializer, string $source)
public function __construct(EventBridgeClient $eventBridge, SerializerInterface $serializer, string $source)
{
$this->eventBridge = $sns;
$this->eventBridge = $eventBridge;
$this->serializer = $serializer ?? new PhpSerializer;
$this->source = $source;
}
Expand Down
16 changes: 6 additions & 10 deletions src/Service/EventBridge/EventBridgeTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@

namespace Bref\Symfony\Messenger\Service\EventBridge;

use Psr\Container\ContainerInterface;
use AsyncAws\EventBridge\EventBridgeClient;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

final class EventBridgeTransportFactory implements TransportFactoryInterface
{
/** @var ContainerInterface */
private $container;
/** @var EventBridgeClient */
private $eventBridge;

public function __construct(ContainerInterface $container)
public function __construct(EventBridgeClient $eventBridge)
{
$this->container = $container;
$this->eventBridge = $eventBridge;
}

public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
{
$source = substr($dsn, strlen('eventbridge://'));

$eventBridge = $this->container->get('bref.messenger.eventbridge_client');

return new EventBridgeTransport($eventBridge, $serializer, $source);
return new EventBridgeTransport($this->eventBridge, $serializer, substr($dsn, strlen('eventbridge://')));
}

public function supports(string $dsn, array $options): bool
Expand Down
14 changes: 6 additions & 8 deletions src/Service/Sns/SnsTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@

namespace Bref\Symfony\Messenger\Service\Sns;

use Psr\Container\ContainerInterface;
use AsyncAws\Sns\SnsClient;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

final class SnsTransportFactory implements TransportFactoryInterface
{
/** @var ContainerInterface */
private $container;
/** @var SnsClient */
private $sns;

public function __construct(ContainerInterface $container)
public function __construct(SnsClient $sns)
{
$this->container = $container;
$this->sns = $sns;
}

public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
{
$sns = $this->container->get('bref.messenger.sns_client');

return new SnsTransport($sns, $serializer, substr($dsn, 6));
return new SnsTransport($this->sns, $serializer, substr($dsn, 6));
}

public function supports(string $dsn, array $options): bool
Expand Down

0 comments on commit c790986

Please sign in to comment.