bug #33922 [Cache] remove implicit dependency on symfony/filesystem (nicolas-grekas)
This PR was merged into the 4.3 branch.
Discussion
----------
[Cache] remove implicit dependency on symfony/filesystem
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
/cc @andrerom for review
Commits
-------
85f27f270e
[Cache] remove implicit dependency on symfony/filesystem
This commit is contained in:
commit
6f58438f7c
@ -15,7 +15,6 @@ use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
|
||||
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
||||
use Symfony\Component\Cache\PruneableInterface;
|
||||
use Symfony\Component\Cache\Traits\FilesystemTrait;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* Stores tag id <> cache id relationship as a symlink, and lookup on invalidation calls.
|
||||
@ -28,8 +27,8 @@ use Symfony\Component\Filesystem\Filesystem;
|
||||
class FilesystemTagAwareAdapter extends AbstractTagAwareAdapter implements PruneableInterface
|
||||
{
|
||||
use FilesystemTrait {
|
||||
doSave as doSaveCache;
|
||||
doDelete as doDeleteCache;
|
||||
doSave as private doSaveCache;
|
||||
doDelete as private doDeleteCache;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,11 +36,6 @@ class FilesystemTagAwareAdapter extends AbstractTagAwareAdapter implements Prune
|
||||
*/
|
||||
private const TAG_FOLDER = 'tags';
|
||||
|
||||
/**
|
||||
* @var Filesystem|null
|
||||
*/
|
||||
private $fs;
|
||||
|
||||
public function __construct(string $namespace = '', int $defaultLifetime = 0, string $directory = null, MarshallerInterface $marshaller = null)
|
||||
{
|
||||
$this->marshaller = $marshaller ?? new DefaultMarshaller();
|
||||
@ -56,7 +50,6 @@ class FilesystemTagAwareAdapter extends AbstractTagAwareAdapter implements Prune
|
||||
{
|
||||
$failed = $this->doSaveCache($values, $lifetime);
|
||||
|
||||
$fs = $this->getFilesystem();
|
||||
// Add Tags as symlinks
|
||||
foreach ($addTagData as $tagId => $ids) {
|
||||
$tagFolder = $this->getTagFolder($tagId);
|
||||
@ -66,12 +59,15 @@ class FilesystemTagAwareAdapter extends AbstractTagAwareAdapter implements Prune
|
||||
}
|
||||
|
||||
$file = $this->getFile($id);
|
||||
$fs->symlink($file, $this->getFile($id, true, $tagFolder));
|
||||
|
||||
if (!@symlink($file, $this->getFile($id, true, $tagFolder))) {
|
||||
@unlink($file);
|
||||
$failed[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unlink removed Tags
|
||||
$files = [];
|
||||
foreach ($removeTagData as $tagId => $ids) {
|
||||
$tagFolder = $this->getTagFolder($tagId);
|
||||
foreach ($ids as $id) {
|
||||
@ -79,10 +75,9 @@ class FilesystemTagAwareAdapter extends AbstractTagAwareAdapter implements Prune
|
||||
continue;
|
||||
}
|
||||
|
||||
$files[] = $this->getFile($id, false, $tagFolder);
|
||||
@unlink($this->getFile($id, false, $tagFolder));
|
||||
}
|
||||
}
|
||||
$fs->remove($files);
|
||||
|
||||
return $failed;
|
||||
}
|
||||
@ -95,15 +90,12 @@ class FilesystemTagAwareAdapter extends AbstractTagAwareAdapter implements Prune
|
||||
$ok = $this->doDeleteCache($ids);
|
||||
|
||||
// Remove tags
|
||||
$files = [];
|
||||
$fs = $this->getFilesystem();
|
||||
foreach ($tagData as $tagId => $idMap) {
|
||||
$tagFolder = $this->getTagFolder($tagId);
|
||||
foreach ($idMap as $id) {
|
||||
$files[] = $this->getFile($id, false, $tagFolder);
|
||||
@unlink($this->getFile($id, false, $tagFolder));
|
||||
}
|
||||
}
|
||||
$fs->remove($files);
|
||||
|
||||
return $ok;
|
||||
}
|
||||
@ -153,11 +145,6 @@ class FilesystemTagAwareAdapter extends AbstractTagAwareAdapter implements Prune
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getFilesystem(): Filesystem
|
||||
{
|
||||
return $this->fs ?? $this->fs = new Filesystem();
|
||||
}
|
||||
|
||||
private function getTagFolder(string $tagId): string
|
||||
{
|
||||
return $this->getFile($tagId, false, $this->directory.self::TAG_FOLDER.\DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR;
|
||||
|
Reference in New Issue
Block a user