Completed
Push — master ( 638d86...a7c2d2 )
by Kamil
22:18
created

StringFieldType::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Component\Grid\FieldTypes;
13
14
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
15
use Sylius\Component\Grid\Definition\Field;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18
/**
19
 * @author Paweł Jędrzejewski <[email protected]>
20
 */
21
class StringFieldType implements FieldTypeInterface
22
{
23
    /**
24
     * @var DataExtractorInterface
25
     */
26
    private $dataExtractor;
27
28
    /**
29
     * @param DataExtractorInterface $dataExtractor
30
     */
31
    public function __construct(DataExtractorInterface $dataExtractor)
32
    {
33
        $this->dataExtractor = $dataExtractor;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function render(Field $field, $data, array $options)
40
    {
41
        $value = $this->dataExtractor->get($field, $data);
42
43
        return is_string($value) ? htmlspecialchars($value) : $value;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function configureOptions(OptionsResolver $resolver)
50
    {
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getName()
57
    {
58
        return 'string';
59
    }
60
}
61