Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove container injection in fixture classes #802

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions Loader/SymfonyFixturesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
use LogicException;
use ReflectionClass;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

use function array_key_exists;
use function array_values;
use function get_class;
use function sprintf;
use function trigger_deprecation;

final class SymfonyFixturesLoader extends Loader implements SymfonyFixturesLoaderInterface
{
Expand All @@ -29,11 +26,6 @@ final class SymfonyFixturesLoader extends Loader implements SymfonyFixturesLoade
/** @var array<string, array<string, bool>> */
private array $groupsFixtureMapping = [];

public function __construct(
private ContainerInterface $container,
) {
}

/**
* @internal
*
Expand Down Expand Up @@ -68,12 +60,6 @@ public function addFixture(FixtureInterface $fixture): void
$this->addGroupsFixtureMapping($class, $fixture::getGroups());
}

if ($fixture instanceof ContainerAwareInterface) {
trigger_deprecation('doctrine/mongodb-odm-bundle', '4.7', 'Implementing "%s" with "%s" is deprecated, use dependency injection instead.', ContainerAwareInterface::class, FixtureInterface::class);

$fixture->setContainer($this->container);
}

parent::addFixture($fixture);
}

Expand Down
4 changes: 1 addition & 3 deletions Resources/config/mongodb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@
<!-- listeners -->
<service id="doctrine_mongodb.odm.listeners.resolve_target_document" class="%doctrine_mongodb.odm.listeners.resolve_target_document.class%" public="false" />

<service id="doctrine_mongodb.odm.symfony.fixtures.loader" class="Doctrine\Bundle\MongoDBBundle\Loader\SymfonyFixturesLoader" public="false">
<argument type="service" id="service_container" />
</service>
<service id="doctrine_mongodb.odm.symfony.fixtures.loader" class="Doctrine\Bundle\MongoDBBundle\Loader\SymfonyFixturesLoader" public="false" />
</services>
</container>
2 changes: 2 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ UPGRADE FROM 4.x to 5.0
used directly or extended.
* Remove support of Annotation mapping, you should use Attributes or XML instead.
* Remove `--service` option from `doctrine:mongodb:fixtures:load` command
* Remove automatic injection of the container in fixtures classes implementing
`ContainerAwareInterface`. You should use dependency injection instead.
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
<code>children</code>
</UndefinedMethod>
</file>
<file src="Loader/SymfonyFixturesLoader.php">
<ContainerDependency>
<code>private ContainerInterface $container</code>
</ContainerDependency>
</file>
<file src="Tests/Form/Type/GuesserTestType.php">
<MissingTemplateParam>
<code>GuesserTestType</code>
Expand Down