|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Superdesk Web Publisher Seo Bundle. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright 2019 Sourcefabric z.ú. and contributors. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please see the |
|
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright 2019 Sourcefabric z.ú |
|
14
|
|
|
* @license http://www.superdesk.org/license |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace SWP\Bundle\SeoBundle\DependencyInjection; |
|
18
|
|
|
|
|
19
|
|
|
use SWP\Bundle\StorageBundle\Doctrine\ORM\EntityRepository; |
|
20
|
|
|
use SWP\Component\Seo\Model\SeoImage; |
|
21
|
|
|
use SWP\Component\Seo\Model\SeoImageInterface; |
|
22
|
|
|
use SWP\Component\Seo\Model\SeoMetadata; |
|
23
|
|
|
use SWP\Component\Seo\Model\SeoMetadataInterface; |
|
24
|
|
|
use SWP\Component\Storage\Factory\Factory; |
|
25
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeParentInterface; |
|
26
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
27
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
28
|
|
|
|
|
29
|
|
View Code Duplication |
class Configuration implements ConfigurationInterface |
|
30
|
|
|
{ |
|
31
|
|
|
public function getConfigTreeBuilder(): NodeParentInterface |
|
32
|
|
|
{ |
|
33
|
|
|
$treeBuilder = new TreeBuilder('swp_seo'); |
|
34
|
|
|
$treeBuilder->getRootNode() |
|
|
|
|
|
|
35
|
|
|
->children() |
|
36
|
|
|
->scalarNode('upload_destination')->cannotBeEmpty()->end() |
|
37
|
|
|
->arrayNode('persistence') |
|
38
|
|
|
->addDefaultsIfNotSet() |
|
39
|
|
|
->children() |
|
40
|
|
|
->arrayNode('orm') |
|
41
|
|
|
->addDefaultsIfNotSet() |
|
42
|
|
|
->canBeEnabled() |
|
43
|
|
|
->children() |
|
44
|
|
|
->arrayNode('classes') |
|
45
|
|
|
->addDefaultsIfNotSet() |
|
46
|
|
|
->children() |
|
47
|
|
|
->arrayNode('seo_metadata') |
|
48
|
|
|
->addDefaultsIfNotSet() |
|
49
|
|
|
->children() |
|
50
|
|
|
->scalarNode('model')->cannotBeEmpty()->defaultValue(SeoMetadata::class)->end() |
|
51
|
|
|
->scalarNode('repository')->defaultValue(EntityRepository::class)->end() |
|
52
|
|
|
->scalarNode('factory')->defaultValue(Factory::class)->end() |
|
53
|
|
|
->scalarNode('interface')->defaultValue(SeoMetadataInterface::class)->end() |
|
54
|
|
|
->scalarNode('object_manager_name')->defaultValue(null)->end() |
|
55
|
|
|
->end() |
|
56
|
|
|
->end() |
|
57
|
|
|
->arrayNode('seo_image') |
|
58
|
|
|
->addDefaultsIfNotSet() |
|
59
|
|
|
->children() |
|
60
|
|
|
->scalarNode('model')->cannotBeEmpty()->defaultValue(SeoImage::class)->end() |
|
61
|
|
|
->scalarNode('repository')->defaultValue(EntityRepository::class)->end() |
|
62
|
|
|
->scalarNode('factory')->defaultValue(Factory::class)->end() |
|
63
|
|
|
->scalarNode('interface')->defaultValue(SeoImageInterface::class)->end() |
|
64
|
|
|
->scalarNode('object_manager_name')->defaultValue(null)->end() |
|
65
|
|
|
->end() |
|
66
|
|
|
->end() |
|
67
|
|
|
->end() |
|
68
|
|
|
->end() |
|
69
|
|
|
->end() |
|
70
|
|
|
->end() |
|
71
|
|
|
->end() |
|
72
|
|
|
->end() |
|
73
|
|
|
->end(); |
|
74
|
|
|
|
|
75
|
|
|
return $treeBuilder; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
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: