1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the StfalconStudioDoctrineRedisCacheBundle. |
4
|
|
|
* |
5
|
|
|
* (c) Stfalcon LLC <stfalcon.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace StfalconStudio\DoctrineRedisCacheBundle\DependencyInjection; |
14
|
|
|
|
15
|
|
|
use Doctrine\Migrations\Finder\RecursiveRegexFinder; |
16
|
|
|
use Symfony\Component\Config\FileLocator; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
19
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This is the class that loads and manages StfalconStudioDoctrineRedisCacheBundle configuration. |
23
|
|
|
* |
24
|
|
|
* @author Artem Henvald <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class StfalconStudioDoctrineRedisCacheExtension extends Extension |
27
|
|
|
{ |
28
|
|
|
/** @var RecursiveRegexFinder */ |
29
|
|
|
private $migrationFinder; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor. |
33
|
|
|
*/ |
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
$this->migrationFinder = new RecursiveRegexFinder(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
43
|
|
|
{ |
44
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
45
|
|
|
$loader->load('services.yaml'); |
46
|
|
|
|
47
|
|
|
$container->setParameter('cache_prefix_seed', $this->getLastMigrationVersion($container->getParameter('doctrine_migrations.dir_name'))); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $dir |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function getLastMigrationVersion(string $dir): string |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$migrations = $this->migrationFinder->findMigrations($dir); |
58
|
|
|
|
59
|
|
|
$versions = \array_keys($migrations); |
60
|
|
|
$latest = \end($versions); |
61
|
|
|
|
62
|
|
|
return false !== $latest ? (string) $latest : '0'; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.