Skip to content

Commit

Permalink
Merge pull request #10 from ray-di/revert-cache-adapter
Browse files Browse the repository at this point in the history
Revert deprecated serializable cache adapter
  • Loading branch information
koriym authored Nov 6, 2021
2 parents eaa5ad8 + 7727bd6 commit d4c9119
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 52 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"autoload": {
"psr-4": {
"Ray\\PsrCacheModule\\": ["src/", "src-deprecated"]
"Ray\\PsrCacheModule\\": ["src/"]
}
},
"autoload-dev": {
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<exclude name="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix"/>
</rule>
<!-- Additional Rules -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,19 @@

namespace Ray\PsrCacheModule;

use JetBrains\PhpStorm\Deprecated;
use Serializable;
use Symfony\Component\Cache\Adapter\FilesystemAdapter as OriginAdapter;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;

use function call_user_func_array;
use function func_get_args;

#[Deprecated]
class FilesystemAdapter extends OriginAdapter implements Serializable
{
use Php73BcSerializableTrait;

/** @var array<int, mixed> */
private $args;
use SerializableTrait;

public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, ?MarshallerInterface $marshaller = null)
{
$this->args = func_get_args();
parent::__construct($namespace, $defaultLifetime, $directory, $marshaller);
}

/**
* @inheritDoc
*/
public function __serialize(): array
{
return $this->args;
}

/**
* {@inheritDoc}
*/
public function __unserialize($data)
{
call_user_func_array([$this, '__construct'], $data); // @phpstan-ignore-line
}
}
3 changes: 1 addition & 2 deletions src/LocalCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Ray\PsrCacheModule\Annotation\CacheNamespace;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Adapter\ChainAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter as SymfonyFilesystemAdapter;

use function sys_get_temp_dir;

Expand All @@ -36,7 +35,7 @@ public function get(): ChainAdapter
{
return new ChainAdapter([
new ApcuAdapter($this->namespace),
new SymfonyFilesystemAdapter($this->namespace, 0, $this->cacheDir),
new FilesystemAdapter($this->namespace, 0, $this->cacheDir),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ final public function unserialize($serializedData)
$array = unserialize($serializedData);
$this->__unserialize($array); // @phpstan-ignore-line
}
}
}
26 changes: 1 addition & 25 deletions src-deprecated/PhpFileAdapter.php → src/PhpFileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,18 @@

namespace Ray\PsrCacheModule;

use JetBrains\PhpStorm\Deprecated;
use Serializable;
use Symfony\Component\Cache\Adapter\PhpFilesAdapter as OriginAdapter;

use function call_user_func_array;
use function func_get_args;
use function serialize;
use function unserialize;

#[Deprecated]
class PhpFileAdapter extends OriginAdapter implements Serializable
{
use Php73BcSerializableTrait;

/** @var array<int, mixed> */
private $args;
use SerializableTrait;

public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, bool $appendOnly = false)
{
$this->args = func_get_args();
parent::__construct($namespace, $defaultLifetime, $directory, $appendOnly);
}

/**
* @inheritDoc
*/
public function __serialize(): array
{
return $this->args;
}

/**
* {@inheritDoc}
*/
public function __unserialize($data)
{
call_user_func_array([$this, '__construct'], $data); // @phpstan-ignore-line
}
}
31 changes: 31 additions & 0 deletions src/SerializableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Ray\PsrCacheModule;

use function call_user_func_array;

trait SerializableTrait
{
use Php73BcSerializableTrait;

/** @var array<mixed> */
private $args;

/**
* @return array<mixed>
*/
public function __serialize(): array
{
return $this->args;
}

/**
* @param array<mixed> $data
*/
public function __unserialize(array $data): void
{
call_user_func_array([$this, '__construct'], $data); // @phpstan-ignore-line
}
}

0 comments on commit d4c9119

Please sign in to comment.