Skip to content

Commit

Permalink
add doctrine messenger transport by default
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Sep 21, 2023
1 parent 1c9deb3 commit 2beba80
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"symfony/dotenv": "^5.0|^6.0",
"symfony/mailer": "^5.0|^6.0",
"symfony/messenger": "^5.0|^6.0",
"symfony/doctrine-messenger": "^5.0|^6.0",
"symfony/serializer": "^5.0|^6.0",
"symfony/rate-limiter": "^5.0|^6.0"
},
Expand Down
3 changes: 3 additions & 0 deletions resources/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
use PSX\Framework\Messenger\DefaultTransport;
use PSX\Framework\Messenger\HandlersLocator;
use PSX\Framework\Messenger\SendersLocator;
use PSX\Framework\Messenger\Transport\DoctrineTransportFactory;
use PSX\Framework\Migration\DependencyFactoryFactory;
use PSX\Framework\OAuth2\AuthorizerInterface;
use PSX\Framework\OAuth2\CallbackInterface;
Expand Down Expand Up @@ -298,6 +299,8 @@
->public();

$services->set(MessengerTransport\InMemory\InMemoryTransportFactory::class);
$services->set(DoctrineTransportFactory::class);

$services->set(MessengerTransport\Sync\SyncTransport::class);

$services->set(MessengerTransport\Serialization\PhpSerializer::class);
Expand Down
57 changes: 57 additions & 0 deletions src/Messenger/Transport/DoctrineTransportFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/*
* PSX is an open source PHP framework to develop RESTful APIs.
* For the current version and information visit <https://phpsx.org>
*
* Copyright 2010-2023 Christoph Kappestein <christoph.kappestein@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace PSX\Framework\Messenger\Transport;

use Doctrine\DBAL\Connection as DoctrineConnection;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

/**
* DoctrineTransportFactory
*
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://phpsx.org
*/
class DoctrineTransportFactory implements TransportFactoryInterface
{
private DoctrineConnection $connection;

public function __construct(DoctrineConnection $connection)
{
$this->connection = $connection;
}

public function createTransport(#[\SensitiveParameter] string $dsn, array $options, SerializerInterface $serializer): TransportInterface
{
$connection = new Connection($options, $this->connection);

return new DoctrineTransport($connection, $serializer);
}

public function supports(#[\SensitiveParameter] string $dsn, array $options): bool
{
return str_starts_with($dsn, 'doctrine://');
}
}

0 comments on commit 2beba80

Please sign in to comment.