1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Helper\Uploadable; |
15
|
|
|
|
16
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
17
|
|
|
use Silverback\ApiComponentsBundle\Entity\Core\FileInfo; |
18
|
|
|
use Silverback\ApiComponentsBundle\Repository\Core\FileInfoRepository; |
19
|
|
|
|
20
|
|
|
class FileInfoCacheManager |
21
|
|
|
{ |
22
|
|
|
private EntityManagerInterface $entityManager; |
23
|
|
|
private FileInfoRepository $repository; |
24
|
|
|
|
25
|
7 |
|
public function __construct(EntityManagerInterface $entityManager, FileInfoRepository $fileInfoRepository) |
26
|
|
|
{ |
27
|
7 |
|
$this->entityManager = $entityManager; |
28
|
7 |
|
$this->repository = $fileInfoRepository; |
29
|
7 |
|
} |
30
|
|
|
|
31
|
|
|
public function saveCache(FileInfo $fileInfo): void |
32
|
|
|
{ |
33
|
|
|
$this->entityManager->persist($fileInfo); |
34
|
|
|
$this->entityManager->flush(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function deleteCaches(array $paths, ?array $filters): void |
38
|
|
|
{ |
39
|
|
|
$results = $this->repository->findByPathsAndFilters($paths, $filters); |
40
|
|
|
foreach ($results as $result) { |
41
|
|
|
$this->entityManager->remove($result); |
42
|
|
|
} |
43
|
|
|
$this->entityManager->flush(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function resolveCache(string $path, ?string $filter = null): ?FileInfo |
47
|
|
|
{ |
48
|
|
|
return $this->repository->findOneByPathAndFilter($path, $filter); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|