Skip to content

Commit

Permalink
bug #10680 Fix ChannelCollector related serialization issue in Symfon…
Browse files Browse the repository at this point in the history
…y profiler (ostrolucky)

This PR was merged into the 1.4 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.4
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | unlikely, but possible
| Deprecations?   | no
| Related tickets | fixes #10223
| License         | MIT

This is very annoying long standing issue.

I'm pretty sure this will fix the issue (it does in our case). As a side effect, this is more efficient, as there is less data needed to be serialized. 

This issue is related to circular references inside Channel model. In our case we can reproduce with

```php
$n = new Channel();
$locale = new Locale();

$n->addLocale($locale);
$n->setDefaultLocale($locale);

$this->data = [
    'channel' => null,
    'channels' => [$n],
    'channel_change_support' => $channelChangeSupport,
];
```

inside ChannelCollector


I'm aware changing return type is technically BC break, but it's unlikely somebody uses this class. If this is an issue, please advise how to continue.

Commits
-------

54baf2d Fix ChannelCollector related serialization issue in Symfony profiler
  • Loading branch information
pamil committed Oct 4, 2019
2 parents 366f758 + 54baf2d commit f8ac6c9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Sylius/Bundle/ChannelBundle/Collector/ChannelCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function __construct(

$this->data = [
'channel' => null,
'channels' => $channelRepository->findAll(),
'channels' => array_map([$this, 'pluckChannel'], $channelRepository->findAll()),
'channel_change_support' => $channelChangeSupport,
];
}

public function getChannel(): ?ChannelInterface
public function getChannel(): ?array
{
return $this->data['channel'];
}
Expand All @@ -64,7 +64,7 @@ public function isChannelChangeSupported(): bool
public function collect(Request $request, Response $response, \Exception $exception = null): void
{
try {
$this->data['channel'] = $this->channelContext->getChannel();
$this->data['channel'] = $this->pluckChannel($this->channelContext->getChannel());
} catch (ChannelNotFoundException $exception) {
}
}
Expand All @@ -84,4 +84,13 @@ public function getName(): string
{
return 'sylius.channel_collector';
}

private function pluckChannel(ChannelInterface $channel): array
{
return [
'name' => $channel->getName(),
'hostname' => $channel->getHostname(),
'code' => $channel->getCode(),
];
}
}

0 comments on commit f8ac6c9

Please sign in to comment.