No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
afab044
... +18 ...
98d48f5
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
12 | 12 | ||
13 | 13 | namespace StfalconStudio\DoctrineRedisCacheBundle; |
|
14 | 14 | ||
15 | + | use StfalconStudio\DoctrineRedisCacheBundle\DependencyInjection\Compiler\DetectLastMigrationPass; |
|
16 | + | use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
|
17 | + | use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
15 | 18 | use Symfony\Component\HttpKernel\Bundle\Bundle; |
|
16 | 19 | ||
17 | 20 | /** |
21 | 24 | */ |
|
22 | 25 | class StfalconStudioDoctrineRedisCacheBundle extends Bundle |
|
23 | 26 | { |
|
27 | + | /** |
|
28 | + | * {@inheritdoc} |
|
29 | + | */ |
|
30 | + | public function build(ContainerBuilder $container): void |
|
31 | + | { |
|
32 | + | parent::build($container); |
|
33 | + | ||
34 | + | $container->addCompilerPass(new DetectLastMigrationPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 33); |
|
35 | + | } |
|
24 | 36 | } |
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\Compiler; |
|
14 | + | ||
15 | + | use Doctrine\Migrations\Configuration\Configuration; |
|
16 | + | use Doctrine\Migrations\Finder\MigrationFinder; |
|
17 | + | use Fresh\DoctrineEnumBundle\Exception\InvalidArgumentException; |
|
18 | + | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
19 | + | use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20 | + | ||
21 | + | /** |
|
22 | + | * DetectLastMigrationPass. |
|
23 | + | * |
|
24 | + | * @author Artem Henvald <genvaldartem@gmail.com> |
|
25 | + | */ |
|
26 | + | final class DetectLastMigrationPass implements CompilerPassInterface |
|
27 | + | { |
|
28 | + | /** |
|
29 | + | * {@inheritdoc} |
|
30 | + | */ |
|
31 | + | public function process(ContainerBuilder $container): void |
|
32 | + | { |
|
33 | + | $migrationFinder = $container->get(MigrationFinder::class); |
|
34 | + | if (!$migrationFinder instanceof MigrationFinder) { |
|
35 | + | throw new InvalidArgumentException(\sprintf('Service "%s" is missed in container', MigrationFinder::class)); |
|
36 | + | } |
|
37 | + | ||
38 | + | $configuration = $container->get('doctrine.migrations.configuration'); |
|
39 | + | if (!$configuration instanceof Configuration) { |
|
40 | + | throw new InvalidArgumentException(\sprintf('Service "%s" is missed in container', Configuration::class)); |
|
41 | + | } |
|
42 | + | ||
43 | + | $migrations = []; |
|
44 | + | foreach ($configuration->getMigrationDirectories() as $migrationDirectory) { |
|
45 | + | foreach ($migrationFinder->findMigrations($migrationDirectory) as $migration) { |
|
46 | + | $migrations[] = $migration; |
|
47 | + | } |
|
48 | + | } |
|
49 | + | foreach ($configuration->getMigrationClasses() as $migration) { |
|
50 | + | $migrations[] = $migration; |
|
51 | + | } |
|
52 | + | ||
53 | + | $processedMigrations = []; |
|
54 | + | foreach ($migrations as $migration) { |
|
55 | + | \preg_match('#Version.*#', $migration, $matches); |
|
56 | + | if (!empty($matches[0])) { |
|
57 | + | $processedMigrations[] = $matches[0]; |
|
58 | + | } |
|
59 | + | } |
|
60 | + | ||
61 | + | \sort($processedMigrations); // Sort by name |
|
62 | + | $latest = \end($processedMigrations); |
|
63 | + | ||
64 | + | if (false !== $latest) { |
|
65 | + | $container->setParameter('cache.prefix.seed', (string) $latest); |
|
66 | + | } |
|
67 | + | } |
|
68 | + | } |
12 | 12 | ||
13 | 13 | namespace StfalconStudio\DoctrineRedisCacheBundle\DependencyInjection; |
|
14 | 14 | ||
15 | - | use Doctrine\Migrations\Finder\RecursiveRegexFinder; |
|
16 | 15 | use Symfony\Component\Config\FileLocator; |
|
17 | 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
18 | 17 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
19 | 18 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
20 | 19 | ||
21 | 20 | /** |
|
22 | - | * This is the class that loads and manages StfalconStudioDoctrineRedisCacheBundle configuration. |
|
21 | + | * StfalconStudioDoctrineRedisCacheExtension. |
|
23 | 22 | * |
|
24 | 23 | * @author Artem Henvald <genvaldartem@gmail.com> |
|
25 | 24 | */ |
|
26 | 25 | class StfalconStudioDoctrineRedisCacheExtension extends Extension |
|
27 | 26 | { |
|
28 | - | /** @var RecursiveRegexFinder */ |
|
29 | - | private $migrationFinder; |
|
30 | - | ||
31 | - | /** |
|
32 | - | * Constructor. |
|
33 | - | */ |
|
34 | - | public function __construct() |
|
35 | - | { |
|
36 | - | $this->migrationFinder = new RecursiveRegexFinder(); |
|
37 | - | } |
|
38 | - | ||
39 | 27 | /** |
|
40 | 28 | * {@inheritdoc} |
|
41 | 29 | */ |
44 | 32 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
45 | 33 | $loader->load('services.yaml'); |
|
46 | 34 | ||
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 | - | 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'; |
|
35 | + | $container->setParameter('cache_prefix_seed', '0'); |
|
63 | 36 | } |
|
64 | 37 | } |
Learn more Showing 2 files with coverage changes found.
DependencyInjection/Compiler/DetectLastMigrationPass.php
StfalconStudioDoctrineRedisCacheBundle.php
Files | Complexity | Coverage |
---|---|---|
DependencyInjection | ø | -11.54% 88.46% |
StfalconStudioDoctrineRedisCacheBundle.php | ø | 100.00% |
Project Totals (3 files) | 11 | 89.66% |
#5
98d48f5
782ef0e
ad09504
f5d02a7
476e6f2
ff282ed
0f736ba
e71d57e
ce47765
f665340
16234b4
8cb99a8
45e2d7e
da35bdf
fc4a782
3002c38
bdd1196
05f8aa5
c24985d
afab044