Completed
Pull Request — master (#375)
by Paul
06:11
created

RequestDataSource::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Victoire\Bundle\CriteriaBundle\DataSource;
4
5
6
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
7
use Symfony\Component\HttpFoundation\RequestStack;
8
9
class RequestDataSource
10
{
11
    /**
12
     * @var RequestStack
13
     */
14
    private $requestStack;
15
    private $availableLocales;
16
17
    /**
18
     * RequestCriteria constructor.
19
     *
20
     * @param RequestStack $requestStack
21
     * @param              $availableLocales
22
     */
23
    public function __construct(RequestStack $requestStack, $availableLocales)
24
    {
25
        $this->requestStack = $requestStack;
26
        $this->availableLocales = $availableLocales;
27
    }
28
29
    public function getLocale()
30
    {
31
        return $this->requestStack->getCurrentRequest()->getLocale();
32
    }
33
34
    public function getScheme()
35
    {
36
        return $this->requestStack->getCurrentRequest()->getScheme();
37
    }
38
39
40
    public function getLocaleFormParams()
41
    {
42
        return [
43
            'type' => ChoiceType::class,
44
            'options' => [
45
                'choices' => $this->availableLocales,
46
            ]
47
        ];
48
    }
49
    public function getSchemeFormParams()
50
    {
51
        return [
52
            'type' => ChoiceType::class,
53
            'options' => [
54
                'choices' => [
55
                    'http' => 'http',
56
                    'https' => 'https'
57
                ],
58
            ]
59
        ];
60
    }
61
}
62