Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable serialization of the connection #264

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Concerns/SerializesConnections.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function __serialize(): array
{
return [
'id' => $this->id(),
'identifier' => $this->identifier(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark as ready for review when updated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identifier isn't a direct property of the Connection object being serialized, but was incorrectly being set as such when the object gets unserialized. This was causing PHPStan to fail static analysis.

The socket's raw identifier is resolved from the underlying WebSocketConnection which is passed in Connection's constructor. For this reason, it was removed from the Connection serialization, which currently only stores the "normalized" socket ID as one of its properties.

Maybe this PR needs more work to try and resurrect the entire connection when unserialized. Although that could be quite a rabbit hole.

'application' => $this->app()->id(),
'origin' => $this->origin(),
'lastSeenAt' => $this->lastSeenAt,
Expand All @@ -29,7 +28,6 @@ public function __serialize(): array
public function __unserialize(array $values): void
{
$this->id = $values['id'];
$this->identifier = $values['identifier'];
$this->application = app(ApplicationProvider::class)->findById($values['application']);
$this->origin = $values['origin'];
$this->lastSeenAt = $values['lastSeenAt'] ?? null;
Expand Down
3 changes: 2 additions & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Laravel\Reverb;

use Laravel\Reverb\Concerns\GeneratesIdentifiers;
use Laravel\Reverb\Concerns\SerializesConnections;
use Laravel\Reverb\Contracts\Connection as ConnectionContract;
use Laravel\Reverb\Events\MessageSent;
use Ratchet\RFC6455\Messaging\Frame;

class Connection extends ConnectionContract
{
use GeneratesIdentifiers;
use GeneratesIdentifiers, SerializesConnections;

/**
* The normalized socket ID.
Expand Down