Dependency-inject fixtures.
This commit is contained in:
parent
cdccaecbf5
commit
14de279bdf
|
@ -379,6 +379,8 @@ return [
|
|||
* Controller Groups
|
||||
*/
|
||||
|
||||
'App\Entity\Fixture\*' => DI\autowire(),
|
||||
|
||||
'App\Controller\Admin\*Controller' => DI\autowire(),
|
||||
|
||||
'App\Controller\Api\*Controller' => DI\autowire(),
|
||||
|
|
|
@ -11,6 +11,7 @@ use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
|||
use Doctrine\ORM\EntityManager;
|
||||
use InfluxDB\Database;
|
||||
use InfluxDB\Point;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SetupFixturesCommand extends CommandAbstract
|
||||
|
@ -18,11 +19,31 @@ class SetupFixturesCommand extends CommandAbstract
|
|||
public function __invoke(
|
||||
SymfonyStyle $io,
|
||||
EntityManager $em,
|
||||
ContainerInterface $di,
|
||||
Database $influx,
|
||||
Settings $settings
|
||||
) {
|
||||
$loader = new Loader();
|
||||
$loader->loadFromDirectory($settings[Settings::BASE_DIR] . '/src/Entity/Fixture');
|
||||
|
||||
// Dependency-inject the fixtures and load them.
|
||||
$fixturesDir = $settings[Settings::BASE_DIR] . '/src/Entity/Fixture';
|
||||
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($fixturesDir),
|
||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
||||
);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
// Skip dotfiles
|
||||
if (($fileName = $file->getBasename('.php')) == $file->getBasename()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$className = 'App\\Entity\\Fixture\\' . $fileName;
|
||||
$fixture = $di->get($className);
|
||||
|
||||
$loader->addFixture($fixture);
|
||||
}
|
||||
|
||||
$purger = new ORMPurger($em);
|
||||
$executor = new ORMExecutor($em, $purger);
|
||||
|
@ -47,7 +68,7 @@ class SetupFixturesCommand extends CommandAbstract
|
|||
|
||||
$influx_points[] = new Point(
|
||||
'station.' . $station->getId() . '.listeners',
|
||||
$station_listeners,
|
||||
(float)$station_listeners,
|
||||
[],
|
||||
['station' => $station->getId()],
|
||||
$day
|
||||
|
@ -56,7 +77,7 @@ class SetupFixturesCommand extends CommandAbstract
|
|||
|
||||
$influx_points[] = new Point(
|
||||
'station.all.listeners',
|
||||
$day_listeners,
|
||||
(float)$day_listeners,
|
||||
[],
|
||||
['station' => 0],
|
||||
$day
|
||||
|
|
Loading…
Reference in New Issue