File tree Expand file tree Collapse file tree 4 files changed +84
-1
lines changed
Expand file tree Collapse file tree 4 files changed +84
-1
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,6 @@ interface CacheTagRepositoryInterface
99 public function getById (int $ id ):? CacheTagInterface ;
1010
1111 public function getByTag (string $ tag ):? CacheTagInterface ;
12+
13+ public function save (CacheTagInterface $ cacheTag ): void ;
1214}
Original file line number Diff line number Diff line change 55use Firegento \CacheWarmup \Api \CacheTagRepositoryInterface ;
66use Firegento \CacheWarmup \Api \Data \CacheTagInterface ;
77use Firegento \CacheWarmup \Api \Data \CacheTagInterfaceFactory ;
8+ use Firegento \CacheWarmup \Model \Route \Query \SaveTag ;
89use Firegento \CacheWarmup \Model \Tag \Query \GetById ;
910use Firegento \CacheWarmup \Model \Tag \Query \GetByTag ;
1011
@@ -19,13 +20,19 @@ class CacheTagRepository implements CacheTagRepositoryInterface
1920 * @var GetByTag
2021 */
2122 protected $ getByTag ;
23+ /**
24+ * @var SaveTag
25+ */
26+ protected $ saveCommand ;
2227
2328 public function __construct (
2429 GetById $ getById ,
25- GetByTag $ getByTag
30+ GetByTag $ getByTag ,
31+ SaveTag $ saveCommand
2632 ) {
2733 $ this ->getById = $ getById ;
2834 $ this ->getByTag = $ getByTag ;
35+ $ this ->saveCommand = $ saveCommand ;
2936 }
3037
3138 public function getById (int $ id ):? CacheTagInterface
@@ -37,4 +44,9 @@ public function getByTag(string $cacheTag):? CacheTagInterface
3744 {
3845 return $ this ->getByTag ->execute ($ cacheTag );
3946 }
47+
48+ public function save (CacheTagInterface $ cacheTag ): void
49+ {
50+ $ this ->saveCommand ->execute ($ cacheTag );
51+ }
4052}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Firegento \CacheWarmup \Service \Tag ;
4+
5+
6+ use Firegento \CacheWarmup \Api \CacheTagRepositoryInterface ;
7+ use Firegento \CacheWarmup \Api \Data \CacheTagInterface ;
8+
9+ class GetExistingOrNewTagModel
10+ {
11+ /**
12+ * @var CacheTagRepositoryInterface
13+ */
14+ protected $ cacheTagRepository ;
15+ /**
16+ * @var NewTagModelProvider
17+ */
18+ protected $ newTagModelProvider ;
19+
20+ public function __construct (
21+ CacheTagRepositoryInterface $ cacheTagRepository ,
22+ NewTagModelProvider $ newTagModelProvider
23+ ) {
24+ $ this ->cacheTagRepository = $ cacheTagRepository ;
25+ $ this ->newTagModelProvider = $ newTagModelProvider ;
26+ }
27+
28+ public function getByTag (string $ cacheTag ): CacheTagInterface
29+ {
30+ $ cacheTag = $ this ->cacheTagRepository ->getByTag ($ cacheTag );
31+
32+ if (!$ cacheTag ) {
33+ $ cacheTag = $ this ->newTagModelProvider ->createForTag ($ cacheTag );
34+ $ this ->cacheTagRepository ->save ($ cacheTag );
35+ $ cacheTag = $ this ->cacheTagRepository ->getByTag ($ cacheTag );
36+ }
37+
38+ return $ cacheTag ;
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Firegento \CacheWarmup \Service \Tag ;
4+
5+
6+ use Firegento \CacheWarmup \Api \Data \CacheTagInterface ;
7+ use Firegento \CacheWarmup \Api \Data \CacheTagInterfaceFactory ;
8+
9+ class NewTagModelProvider
10+ {
11+ /**
12+ * @var CacheTagInterfaceFactory
13+ */
14+ protected $ cacheTagInterfaceFactory ;
15+
16+ public function __construct (CacheTagInterfaceFactory $ cacheTagInterfaceFactory )
17+ {
18+ $ this ->cacheTagInterfaceFactory = $ cacheTagInterfaceFactory ;
19+ }
20+
21+ public function createForTag (string $ cacheTag ): CacheTagInterface
22+ {
23+ /** @var CacheTagInterface $tagModel */
24+ $ tagModel = $ this ->cacheTagInterfaceFactory ->create ();
25+ $ tagModel ->setCacheTag ($ cacheTag );
26+
27+ return $ tagModel ;
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments