This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Added SerializationHelper that handles PostgreSql serialization correctly & replaced all serialization function calls #63
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3ce1bb5
Added serialization for postgresql
55cd16b
Added postgresql serialization support
9db4b8f
Update SerializeClosure.php
1161986
Create Serialization Helper
d866ea5
Merge pull request #1 from blazpezdir/patch-2
c785412
Update SerializationHelper
66f7f94
Update Serialized.php
564c95d
Update SerializedModel.php
370d265
Update Serialized.php
beab6ad
Update SerializeClosure.php
638a683
Update MiddlewareCollectionCast.php
86179a4
Update CallbackCollectionCast.php
4424a48
Rename SerializationHelper to SerializationHelper.php
690a366
Update JobEventListener.php
9442a2a
Update Serialized.php
0ffeb40
Update Serialized.php
b53d805
Update SerializationHelper.php
119c391
Update SerializationHelper.php
aca68c4
Update SerializationHelper.php
73a4b59
Update SerializationHelper.php
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sammyjo20\LaravelHaystack\Helpers; | ||
|
||
use Illuminate\Database\PostgresConnection; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Str; | ||
|
||
class SerializationHelper | ||
{ | ||
/** | ||
* Serialize the given value. | ||
* | ||
* @param mixed $value | ||
* @return string | ||
*/ | ||
public static function serialize(mixed $value) : string | ||
{ | ||
$serialized = serialize($value); | ||
|
||
return DB::connection() instanceof PostgresConnection | ||
? base64_encode($serialized) | ||
: $serialized; | ||
} | ||
|
||
/** | ||
* Unserialize the given value. | ||
* | ||
* @param string $serialized | ||
* @param array $options | ||
* @return mixed | ||
*/ | ||
public static function unserialize(string $serialized, array $options = []) : mixed | ||
{ | ||
if (DB::connection() instanceof PostgresConnection && ! Str::contains($serialized, [':', ';'])) { | ||
$serialized = base64_decode($serialized); | ||
} | ||
|
||
return unserialize($serialized, $options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be using the connection that has been specified on the model instead of the global DB connection? From Laravel's PR:
https://github.com/laravel/framework/pull/36081/files#diff-c46d3e14c232058da1ea59d469b8abc9866c1ced2104eece667c4077b54a5e22R304-R306
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think you are right. This solution only covers the default scenario. I will look into it and make fixes accordingly.