]> Raphaël G. Git Repositories - treebundle/blob - Fixture/TreeFixture.php
Rename resource to asset
[treebundle] / Fixture / TreeFixture.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys TreeBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\TreeBundle\Fixture;
13
14 use Doctrine\Bundle\FixturesBundle\Fixture;
15 use Doctrine\Persistence\ObjectManager;
16
17 use Rapsys\PackBundle\Util\SluggerUtil;
18 use Rapsys\TreeBundle\Entity\Album;
19 use Rapsys\TreeBundle\RapsysTreeBundle;
20
21 use Symfony\Component\DependencyInjection\ContainerInterface;
22
23 /**
24 * {@inheritdoc}
25 */
26 class TreeFixture extends Fixture {
27 /**
28 * Config array
29 */
30 private array $config;
31
32 /**
33 * Air fixtures constructor
34 */
35 public function __construct(private ContainerInterface $container, private SluggerUtil $slugger) {
36 //Retrieve config
37 $this->config = $container->getParameter(RapsysTreeBundle::getAlias());
38 }
39
40 /**
41 * {@inheritDoc}
42 */
43 public function load(ObjectManager $manager) {
44 //Album tree
45 $albumTree = [
46 ];
47
48 //Create titles
49 $albums = [];
50 foreach($albumTree as $albumTitle => $albumPath) {
51 $album = new Album($albumPath, $this->slugger->slug($albumTitle), $albumTitle);
52 $manager->persist($album);
53 $albums[$albumTitle] = $album;
54 unset($album);
55 }
56
57 //Flush to get the ids
58 $manager->flush();
59 }
60 }