Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from koriym/php8.1-serializable
Fix PHP 8.1 deprecation warnings with unserializable symfony cache component support
- Loading branch information
Showing
10 changed files
with
139 additions
and
63 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
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BEAR\QueryRepository; | ||
|
||
use function serialize; | ||
use function unserialize; | ||
|
||
trait Php73BcSerializableTrait | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
final public function serialize() | ||
{ | ||
return serialize($this->__serialize()); | ||
} | ||
|
||
/** | ||
* @psalm-suppress all | ||
* | ||
* {@inheritDoc} | ||
*/ | ||
final public function unserialize($serializedData) | ||
{ | ||
$array = unserialize($serializedData); | ||
$this->__unserialize($array); // @phpstan-ignore-line | ||
} | ||
} |
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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BEAR\QueryRepository; | ||
|
||
use BEAR\RepositoryModule\Annotation\EtagPool; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
use Ray\Di\Di\Inject; | ||
use Ray\Di\InjectorInterface; | ||
use Ray\PsrCacheModule\Annotation\Shared; | ||
use Symfony\Component\Cache\Adapter\AdapterInterface; | ||
use Symfony\Component\Cache\Adapter\TagAwareAdapter; | ||
|
||
use function assert; | ||
|
||
trait ResourceStorageCacheableTrait | ||
{ | ||
use Php73BcSerializableTrait; | ||
|
||
/** | ||
* @var ?InjectorInterface | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
protected $injector; | ||
|
||
/** | ||
* @Inject | ||
*/ | ||
#[Inject] | ||
final public function setInjector(InjectorInterface $injector): void | ||
{ | ||
$this->injector = $injector; | ||
} | ||
|
||
/** | ||
* @return array{logger: RepositoryLoggerInterface, purger: PurgerInterface, uriTag: UriTagInterface, saver: ResourceStorageSaver, knownTagTtl: float, injector: InjectorInterface} | ||
*/ | ||
final public function __serialize(): array | ||
{ | ||
assert($this->injector instanceof InjectorInterface); | ||
|
||
return [ | ||
'logger' => $this->logger, | ||
'purger' => $this->purger, | ||
'uriTag' => $this->uriTag, | ||
'saver' => $this->saver, | ||
'knownTagTtl' => $this->knownTagTtl, | ||
'injector' => $this->injector, | ||
]; | ||
} | ||
|
||
/** | ||
* @param array{logger: RepositoryLoggerInterface, purger: PurgerInterface, uriTag: UriTagInterface, saver: ResourceStorageSaver, knownTagTtl: float, injector: InjectorInterface} $data | ||
*/ | ||
final public function __unserialize(array $data): void | ||
{ | ||
$this->logger = $data['logger']; | ||
$this->purger = $data['purger']; | ||
$this->uriTag = $data['uriTag']; | ||
$this->saver = $data['saver']; | ||
$pool = $data['injector']->getInstance(CacheItemPoolInterface::class, Shared::class); | ||
$etagPool = $data['injector']->getInstance(CacheItemPoolInterface::class, EtagPool::class); | ||
assert($pool instanceof AdapterInterface); | ||
assert($etagPool instanceof AdapterInterface); | ||
$this->roPool = new TagAwareAdapter($pool, $etagPool, $data['knownTagTtl']); | ||
$this->etagPool = new TagAwareAdapter($etagPool, $etagPool, $data['knownTagTtl']); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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