|
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\Bundle\GridBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Bundle\GridBundle\Doctrine\ORM\Driver as DoctrineORMDriver; |
|
15
|
|
|
use Sylius\Bundle\GridBundle\SyliusGridBundle; |
|
16
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
17
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
18
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class Configuration implements ConfigurationInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getConfigTreeBuilder() |
|
29
|
|
|
{ |
|
30
|
|
|
$treeBuilder = new TreeBuilder(); |
|
31
|
|
|
$rootNode = $treeBuilder->root('sylius_grid'); |
|
32
|
|
|
|
|
33
|
|
|
$this->addDriversSection($rootNode); |
|
34
|
|
|
$this->addTemplatesSection($rootNode); |
|
35
|
|
|
$this->addGridsSection($rootNode); |
|
36
|
|
|
|
|
37
|
|
|
return $treeBuilder; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param ArrayNodeDefinition $node |
|
42
|
|
|
*/ |
|
43
|
|
|
private function addDriversSection(ArrayNodeDefinition $node) |
|
44
|
|
|
{ |
|
45
|
|
|
$node |
|
|
|
|
|
|
46
|
|
|
->children() |
|
47
|
|
|
->arrayNode('drivers') |
|
48
|
|
|
->defaultValue([SyliusGridBundle::DRIVER_DOCTRINE_ORM]) |
|
49
|
|
|
->prototype('enum')->values(SyliusGridBundle::getAvailableDrivers())->end() |
|
50
|
|
|
->end() |
|
51
|
|
|
->end() |
|
52
|
|
|
; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param ArrayNodeDefinition $node |
|
57
|
|
|
*/ |
|
58
|
|
|
private function addTemplatesSection(ArrayNodeDefinition $node) |
|
59
|
|
|
{ |
|
60
|
|
|
$node |
|
|
|
|
|
|
61
|
|
|
->children() |
|
62
|
|
|
->arrayNode('templates') |
|
63
|
|
|
->addDefaultsIfNotSet() |
|
64
|
|
|
->children() |
|
65
|
|
|
->arrayNode('filter') |
|
66
|
|
|
->useAttributeAsKey('name') |
|
67
|
|
|
->prototype('scalar')->end() |
|
68
|
|
|
->end() |
|
69
|
|
|
->arrayNode('action') |
|
70
|
|
|
->useAttributeAsKey('name') |
|
71
|
|
|
->prototype('scalar')->end() |
|
72
|
|
|
->end() |
|
73
|
|
|
->end() |
|
74
|
|
|
->end() |
|
75
|
|
|
->end() |
|
76
|
|
|
; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param ArrayNodeDefinition $node |
|
81
|
|
|
*/ |
|
82
|
|
|
private function addGridsSection(ArrayNodeDefinition $node) |
|
83
|
|
|
{ |
|
84
|
|
|
$node |
|
|
|
|
|
|
85
|
|
|
->children() |
|
86
|
|
|
->arrayNode('grids') |
|
87
|
|
|
->useAttributeAsKey('code') |
|
88
|
|
|
->prototype('array') |
|
89
|
|
|
->children() |
|
90
|
|
|
->scalarNode('extends')->cannotBeEmpty()->end() |
|
91
|
|
|
->arrayNode('driver') |
|
92
|
|
|
->addDefaultsIfNotSet() |
|
93
|
|
|
->children() |
|
94
|
|
|
->scalarNode('name')->cannotBeEmpty()->defaultValue(DoctrineORMDriver::NAME)->end() |
|
95
|
|
|
->arrayNode('options') |
|
96
|
|
|
->prototype('variable')->end() |
|
97
|
|
|
->defaultValue([]) |
|
98
|
|
|
->end() |
|
99
|
|
|
->end() |
|
100
|
|
|
->end() |
|
101
|
|
|
->arrayNode('sorting') |
|
102
|
|
|
->performNoDeepMerging() |
|
103
|
|
|
->useAttributeAsKey('name') |
|
104
|
|
|
->prototype('enum')->values(['asc', 'desc'])->cannotBeEmpty()->end() |
|
105
|
|
|
->end() |
|
106
|
|
|
->arrayNode('fields') |
|
107
|
|
|
->useAttributeAsKey('name') |
|
108
|
|
|
->prototype('array') |
|
109
|
|
|
->children() |
|
110
|
|
|
->scalarNode('type')->isRequired()->cannotBeEmpty()->end() |
|
111
|
|
|
->scalarNode('label')->cannotBeEmpty()->end() |
|
112
|
|
|
->scalarNode('path')->cannotBeEmpty()->end() |
|
113
|
|
|
->scalarNode('sortable')->end() |
|
114
|
|
|
->scalarNode('enabled')->defaultTrue()->end() |
|
115
|
|
|
->scalarNode('position')->defaultValue(100)->end() |
|
116
|
|
|
->arrayNode('options') |
|
117
|
|
|
->prototype('variable')->end() |
|
118
|
|
|
->end() |
|
119
|
|
|
->end() |
|
120
|
|
|
->end() |
|
121
|
|
|
->end() |
|
122
|
|
|
->arrayNode('filters') |
|
123
|
|
|
->useAttributeAsKey('name') |
|
124
|
|
|
->prototype('array') |
|
125
|
|
|
->children() |
|
126
|
|
|
->scalarNode('type')->isRequired()->cannotBeEmpty()->end() |
|
127
|
|
|
->scalarNode('label')->cannotBeEmpty()->end() |
|
128
|
|
|
->scalarNode('enabled')->defaultTrue()->end() |
|
129
|
|
|
->scalarNode('template')->end() |
|
130
|
|
|
->scalarNode('position')->defaultValue(100)->end() |
|
131
|
|
|
->arrayNode('options') |
|
132
|
|
|
->prototype('variable')->end() |
|
133
|
|
|
->end() |
|
134
|
|
|
->end() |
|
135
|
|
|
->end() |
|
136
|
|
|
->end() |
|
137
|
|
|
->arrayNode('actions') |
|
138
|
|
|
->useAttributeAsKey('name') |
|
139
|
|
|
->prototype('array') |
|
140
|
|
|
->useAttributeAsKey('name') |
|
141
|
|
|
->prototype('array') |
|
142
|
|
|
->children() |
|
143
|
|
|
->scalarNode('type')->isRequired()->end() |
|
144
|
|
|
->scalarNode('label')->end() |
|
145
|
|
|
->scalarNode('icon')->end() |
|
146
|
|
|
->scalarNode('position')->defaultValue(100)->end() |
|
147
|
|
|
->arrayNode('options') |
|
148
|
|
|
->prototype('variable')->end() |
|
149
|
|
|
->end() |
|
150
|
|
|
->end() |
|
151
|
|
|
->end() |
|
152
|
|
|
->end() |
|
153
|
|
|
->end() |
|
154
|
|
|
->end() |
|
155
|
|
|
->end() |
|
156
|
|
|
->end() |
|
157
|
|
|
->end() |
|
158
|
|
|
; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: