-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
TagFixtures.php
48 lines (41 loc) · 1.17 KB
/
TagFixtures.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AppBundle\DataFixtures\ORM;
use AppBundle\DataFixtures\FixturesTrait;
use AppBundle\Entity\Tag;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
/**
* Defines the sample blog tags to load in the database before running the unit
* and functional tests. Execute this command to load the data.
*
* $ php bin/console doctrine:fixtures:load
*
* See http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html
*
* @author Yonel Ceruto <yonelceruto@gmail.com>
*/
class TagFixtures extends AbstractFixture
{
use FixturesTrait;
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
foreach ($this->getTagNames() as $index => $name) {
$tag = new Tag();
$tag->setName($name);
$manager->persist($tag);
$this->addReference('tag-'.$index, $tag);
}
$manager->flush();
}
}