1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the takeit/AmpHtmlBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Rafał Muszyński <[email protected]> |
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 Takeit\Bundle\AmpHtmlBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* This is the class that validates and merges configuration from your app/config files. |
19
|
|
|
* |
20
|
|
|
* @author Rafał Muszyński <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Configuration implements ConfigurationInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function getConfigTreeBuilder() |
28
|
|
|
{ |
29
|
|
|
$treeBuilder = new TreeBuilder('takeit_amp_html'); |
30
|
|
|
$treeBuilder->getRootNode() |
|
|
|
|
31
|
|
|
->canBeDisabled() |
32
|
|
|
->info('Enable or disable Google AMP HTML support.') |
33
|
|
|
->addDefaultsIfNotSet() |
34
|
|
|
->children() |
35
|
|
|
->arrayNode('theme') |
36
|
|
|
->addDefaultsIfNotSet() |
37
|
|
|
->children() |
38
|
|
|
->scalarNode('loader') |
39
|
|
|
->defaultValue('takeit_amp_html.loader.theme.default') |
40
|
|
|
->cannotBeEmpty() |
41
|
|
|
->end() |
42
|
|
|
->scalarNode('theme_path') |
43
|
|
|
->defaultValue('%kernel.root_dir%/Resources/amp/amp-theme') |
44
|
|
|
->end() |
45
|
|
|
->end() |
46
|
|
|
->end() |
47
|
|
|
->scalarNode('checker') |
48
|
|
|
->defaultValue('takeit_amp_html.checker.default') |
49
|
|
|
->cannotBeEmpty() |
50
|
|
|
->end() |
51
|
|
|
->arrayNode('routing') |
52
|
|
|
->isRequired() |
53
|
|
|
->addDefaultsIfNotSet() |
54
|
|
|
->children() |
55
|
|
|
->arrayNode('route_strategy') |
56
|
|
|
->canBeEnabled() |
57
|
|
|
->addDefaultsIfNotSet() |
58
|
|
|
->children() |
59
|
|
|
->scalarNode('prefix') |
60
|
|
|
->defaultValue('/platform/amp') |
61
|
|
|
->end() |
62
|
|
|
->scalarNode('pattern') |
63
|
|
|
->isRequired() |
64
|
|
|
->cannotBeEmpty() |
65
|
|
|
->end() |
66
|
|
|
->scalarNode('parameter') |
67
|
|
|
->cannotBeEmpty() |
68
|
|
|
->defaultValue('slug') |
69
|
|
|
->end() |
70
|
|
|
->scalarNode('parameterRegex') |
71
|
|
|
->defaultValue('.+') |
72
|
|
|
->info('Parameter\'s regular expression.') |
73
|
|
|
->end() |
74
|
|
|
->end() |
75
|
|
|
->end() |
76
|
|
|
->arrayNode('parameter_strategy') |
77
|
|
|
->canBeEnabled() |
78
|
|
|
->end() |
79
|
|
|
->scalarNode('controller') |
80
|
|
|
->defaultValue('takeit_amp_html.amp_controller:viewAction') |
81
|
|
|
->end() |
82
|
|
|
->end() |
83
|
|
|
->end() |
84
|
|
|
->scalarNode('model') |
85
|
|
|
->cannotBeEmpty() |
86
|
|
|
->isRequired() |
87
|
|
|
->info('Fully qualified class name of your model.') |
88
|
|
|
->end() |
89
|
|
|
->scalarNode('converter') |
90
|
|
|
->defaultValue('takeit_amp_html.amp_converter') |
91
|
|
|
->info('Custom converter service id.') |
92
|
|
|
->end() |
93
|
|
|
->end() |
94
|
|
|
; |
95
|
|
|
|
96
|
|
|
return $treeBuilder; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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: