generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move serialization responsibility to cache objects
- Loading branch information
Showing
8 changed files
with
88 additions
and
42 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EriBloo\CacheObjects\Contracts; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
interface CacheValueModifier | ||
{ | ||
/** | ||
* @return T | ||
*/ | ||
public function onLoad(string $value): mixed; | ||
|
||
/** | ||
* @param T $value | ||
*/ | ||
public function onSave(mixed $value): string; | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EriBloo\CacheObjects\ValueObjects\Values; | ||
|
||
use EriBloo\CacheObjects\Contracts\CacheValueModifier; | ||
|
||
/** | ||
* @template TValue | ||
* | ||
* @implements CacheValueModifier<TValue> | ||
*/ | ||
final readonly class SerializeModifier implements CacheValueModifier | ||
{ | ||
/** | ||
* @param class-string[]|bool $allowedClasses | ||
*/ | ||
public function __construct( | ||
private array|bool $allowedClasses = true, | ||
) {} | ||
|
||
public function onLoad(string $value): mixed | ||
{ | ||
return unserialize($value, [ | ||
'allowed_classes' => $this->allowedClasses, | ||
]); | ||
} | ||
|
||
public function onSave(mixed $value): string | ||
{ | ||
return serialize($value); | ||
} | ||
} |
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