Skip to content

Commit 1b86257

Browse files
committed
Replaced the obsolete containerawareinterface with own implementation
1 parent 0f5fb99 commit 1b86257

File tree

3 files changed

+88
-5
lines changed

3 files changed

+88
-5
lines changed

migrations/Version20221114193325.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44

55
namespace DoctrineMigrations;
66

7+
use App\Doctrine\Migration\ContainerAwareMigrationInterface;
78
use App\Migration\AbstractMultiPlatformMigration;
89
use App\Migration\WithPermPresetsTrait;
910
use App\Services\UserSystem\PermissionPresetsHelper;
1011
use Doctrine\DBAL\Connection;
1112
use Doctrine\DBAL\Schema\Schema;
1213
use Psr\Log\LoggerInterface;
13-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1414

15-
/**
16-
* Auto-generated Migration: Please modify to your needs!
17-
*/
18-
final class Version20221114193325 extends AbstractMultiPlatformMigration implements ContainerAwareInterface
15+
final class Version20221114193325 extends AbstractMultiPlatformMigration implements ContainerAwareMigrationInterface
1916
{
2017
use WithPermPresetsTrait;
2118

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published
9+
* by the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
24+
namespace App\Doctrine\Migration;
25+
26+
use App\Services\UserSystem\PermissionPresetsHelper;
27+
use Doctrine\Migrations\AbstractMigration;
28+
use Doctrine\Migrations\Version\MigrationFactory;
29+
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
30+
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
31+
use Symfony\Component\DependencyInjection\ContainerInterface;
32+
33+
#[AsDecorator("doctrine.migrations.migrations_factory")]
34+
class ContainerAwareMigrationFactory implements MigrationFactory
35+
{
36+
public function __construct(private readonly MigrationFactory $decorated,
37+
//List all services that should be available in migrations here
38+
#[AutowireLocator([
39+
PermissionPresetsHelper::class
40+
])]
41+
private readonly ContainerInterface $container)
42+
{
43+
}
44+
45+
public function createVersion(string $migrationClassName): AbstractMigration
46+
{
47+
$migration = $this->decorated->createVersion($migrationClassName);
48+
49+
if ($migration instanceof ContainerAwareMigrationInterface) {
50+
$migration->setContainer($this->container);
51+
}
52+
53+
return $migration;
54+
}
55+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published
9+
* by the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
24+
namespace App\Doctrine\Migration;
25+
26+
use Symfony\Component\DependencyInjection\ContainerInterface;
27+
28+
interface ContainerAwareMigrationInterface
29+
{
30+
public function setContainer(?ContainerInterface $container = null): void;
31+
}

0 commit comments

Comments
 (0)