Skip to content

Commit

Permalink
fix(Serializer): Do not use class-string type-hint it breaks JSON s…
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Sep 29, 2023
1 parent 25c80a0 commit 9ffaf6e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ framework:
# failure_transport: failed
reset_on_message: true
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
# https://symfony.com/doc/current/messenger.html#transport-configuration
async:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
# Use JSON message to be able to decode them in a NodeJS worker
serializer: messenger.transport.symfony_serializer
failed: 'doctrine://default?queue_name=failed'
sync: 'sync://'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
abstract class AbstractSolrMessage implements AsyncMessage
{
/**
* @var class-string
* Cannot typehint with class-string: breaks Symfony Serializer 5.4
* @var string
*/
protected string $classname;
/**
Expand All @@ -18,7 +19,7 @@ abstract class AbstractSolrMessage implements AsyncMessage
protected mixed $identifier;

/**
* @param class-string $classname
* @param string $classname
* @param mixed $identifier
*/
public function __construct(string $classname, mixed $identifier)
Expand All @@ -28,7 +29,7 @@ public function __construct(string $classname, mixed $identifier)
}

/**
* @return class-string
* @return string
*/
public function getClassname(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function __invoke(SolrDeleteMessage $message): void
{
try {
if (!empty($message->getIdentifier())) {
// Cannot typehint with class-string: breaks Symfony Serializer 5.4
// @phpstan-ignore-next-line
$this->indexerFactory->getIndexerFor($message->getClassname())->delete($message->getIdentifier());
}
} catch (SolrServerNotAvailableException $exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function __invoke(SolrReindexMessage $message): void
{
try {
if (!empty($message->getIdentifier())) {
// Cannot typehint with class-string: breaks Symfony Serializer 5.4
// @phpstan-ignore-next-line
$this->indexerFactory->getIndexerFor($message->getClassname())->index($message->getIdentifier());
}
} catch (SolrServerNotAvailableException $exception) {
Expand Down

0 comments on commit 9ffaf6e

Please sign in to comment.