<?php
namespace App\EventSubscriber;
use App\Event\FixtureLoadedEvent;
use App\Factory\AssetFactory;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Filesystem\Filesystem;
class FixtureEventSubscriber implements EventSubscriberInterface
{
protected Filesystem $filesystem;
protected string $projectDir;
public function __construct(
Filesystem $filesystem,
string $projectDir
) {
$this->filesystem = $filesystem;
$this->projectDir = $projectDir;
}
public static function getSubscribedEvents()
{
return [
FixtureLoadedEvent::class => 'fixturesLoaded',
];
}
public function fixturesLoaded()
{
$fixtureDir = sprintf('%s/%s', $this->projectDir, AssetFactory::TEMP_FOLDER);
if (!$this->filesystem->exists($fixtureDir)) {
return;
}
$this->filesystem->remove($fixtureDir);
}
}