Completed
Push — master ( c211bb...9af78c )
by Eric
39:31 queued 32:31
created

AbstractLocaleFixture::createLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\LocaleBundle\DataFixtures;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use Lug\Bundle\ResourceBundle\DataFixtures\ORM\AbstractDriverFixture;
16
use Symfony\Component\Intl\Intl;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
abstract class AbstractLocaleFixture extends AbstractDriverFixture
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function doLoad(ObjectManager $manager)
27
    {
28
        $defaultCode = $this->getContainer()->getParameter('lug.locale');
29
30
        foreach (array_keys(Intl::getLocaleBundle()->getLocaleNames()) as $code) {
31
            $locale = $this->getFactory()->create([
32
                'code'     => $code,
33
                'enabled'  => $code === $defaultCode,
34
                'required' => $code === $defaultCode,
35
            ]);
36
37
            $manager->persist($locale);
38
            $this->setReference('lug.locale.'.$code, $locale);
39
        }
40
41
        $manager->flush();
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    protected function getResourceName()
48
    {
49
        return 'locale';
50
    }
51
}
52