1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Psi\Component\Grid\Column; |
6
|
|
|
|
7
|
|
|
use Psi\Component\Grid\CellInterface; |
8
|
|
|
use Psi\Component\Grid\ColumnInterface; |
9
|
|
|
use Psi\Component\Grid\GridContext; |
10
|
|
|
use Psi\Component\Grid\View\Cell; |
11
|
|
|
use Psi\Component\Grid\View\Header; |
12
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
13
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
14
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
15
|
|
|
|
16
|
|
|
class PropertyColumn implements ColumnInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var PropertyAccessor |
20
|
|
|
*/ |
21
|
|
|
private $accessor; |
22
|
|
|
|
23
|
|
|
public function __construct(PropertyAccessorInterface $propertyAccessor = null) |
24
|
|
|
{ |
25
|
|
|
$this->accessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function buildCell(Cell $cell, array $options) |
29
|
|
|
{ |
30
|
|
|
$property = $options['property']; |
31
|
|
|
$cell->template = 'Property'; |
32
|
|
|
$cell->value = $this->accessor->getValue($cell->context, $property); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function configureOptions(OptionsResolver $options) |
36
|
|
|
{ |
37
|
|
|
$options->setDefault('property', null); |
38
|
|
|
$options->setAllowedTypes('property', ['string', 'null']); |
39
|
|
|
$options->setNormalizer('property', function (OptionsResolver $options, $value) { |
40
|
|
|
if (null !== $value) { |
41
|
|
|
return $value; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $options['column_name']; |
45
|
|
|
}); |
46
|
|
|
$options->setNormalizer('sort_field', function (OptionsResolver $options, $value) { |
47
|
|
|
if (null !== $value) { |
48
|
|
|
return $value; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $options['column_name']; |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getParent() |
56
|
|
|
{ |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..