-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Feature Request: Add preLoad
and postLoad
events to enhance fixture loading management
#71
Comments
preLoad
and postLoad
Events to Enhance Fixture Loading ManagementpreLoad
and postLoad
events to enhance fixture loading management
Hi @EdouardCourty! I'm glad this bundle helped you!
Just to clarify as I don't really understand the use case: the goal here is to know that the fixtures have been loaded? If so wouldn't it be sufficient to register a decorator? (pseudo-code, I did not execute this): class HautelookAliceLoaderEventDispatcher {
construct(
private EventDispatcherInterface $eventDispatcher,
private \Hautelook\AliceBundle\LoaderInterface $decoratedLoader,
) {}
public function load(
Application $application,
EntityManagerInterface $manager,
array $bundles,
string $environment,
bool $append,
bool $purgeWithTruncate,
bool $noBundles = false
): array {
$this->eventDispatcher->dispatch(new FixturesLoadingWasStarted());
$result = $this->decoratedLoader->load(...func_get_args());
$this->eventDispatcher->dispatch(new FixturesWereLoaded());
return $result;
}
} // config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use App\DecoratingMailer;
use App\Mailer;
return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Mailer::class);
$services->set(\Hautelook\AliceBundle\LoaderInterface::class)
->decorate(HautelookAliceLoaderEventDispatcher::class)
->args([service('.inner')]);
}; ? I don't particularly mind the of having it in the core, but we'll have to be mindful that the event dispatcher may not always be available and to not fail if the dependency is not present. |
That approach would work, I simply thought it could be a cool feature to have in the bundle, and could only be enabled if the EventDispatcher is available. I don't have time to submit a PR for now, I'll do it if I ever find the time! |
Hi there! π
First off, thank you for this fantastic bundle β it's been a pleasure to use and has made fixture management so much simpler! π
I've come across a scenario while building an app that leverages Doctrine's
onFlush
andpostFlush
events to trigger additional logic. While this works great under normal circumstances, Iβd like to ensure these events are bypassed when loading fixtures.In the past, Iβve tried using a special environment parameter to manage this, but Iβve found it to be somewhat flaky and not the most reliable or elegant solution. Iβve also considered implementing a stateful service to track whether fixtures are being loaded. However, such an approach would greatly benefit from explicit events fired by the fixture loader itself.
Would it be possible to introduce events like
preLoad
andpostLoad
into this bundle? This addition would make it much easier to handle cases like mine and would likely be helpful for others too.Iβd be happy to contribute and submit a PR for this feature if it aligns with the goals of the project.
Thank you for considering this suggestion! Looking forward to hearing your thoughts. π
The text was updated successfully, but these errors were encountered: