1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Lucene Search package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\LuceneSearchBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Ivory\LuceneSearchBundle\Model\LuceneManager; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author GeLo <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Configuration implements ConfigurationInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
27 |
|
public function getConfigTreeBuilder() |
27
|
|
|
{ |
28
|
27 |
|
$treeBuilder = new TreeBuilder(); |
29
|
|
|
$treeBuilder |
|
|
|
|
30
|
27 |
|
->root('ivory_lucene_search') |
31
|
27 |
|
->useAttributeAsKey('name') |
32
|
27 |
|
->prototype('array') |
33
|
27 |
|
->children() |
34
|
27 |
|
->scalarNode('path') |
35
|
27 |
|
->isRequired() |
36
|
27 |
|
->end() |
37
|
27 |
|
->scalarNode('analyzer') |
38
|
27 |
|
->defaultValue(LuceneManager::DEFAULT_ANALYZER) |
39
|
27 |
|
->end() |
40
|
27 |
|
->scalarNode('max_buffered_docs') |
41
|
27 |
|
->defaultValue(LuceneManager::DEFAULT_MAX_BUFFERED_DOCS) |
42
|
27 |
|
->end() |
43
|
27 |
|
->scalarNode('max_merge_docs') |
44
|
27 |
|
->defaultValue(LuceneManager::DEFAULT_MAX_MERGE_DOCS) |
45
|
27 |
|
->end() |
46
|
27 |
|
->scalarNode('merge_factor') |
47
|
27 |
|
->defaultValue(LuceneManager::DEFAULT_MERGE_FACTOR) |
48
|
27 |
|
->end() |
49
|
27 |
|
->scalarNode('permissions') |
50
|
27 |
|
->defaultValue(LuceneManager::DEFAULT_PERMISSIONS) |
51
|
27 |
|
->end() |
52
|
27 |
|
->scalarNode('auto_optimized') |
53
|
27 |
|
->defaultValue(LuceneManager::DEFAULT_AUTO_OPTIMIZED) |
54
|
27 |
|
->end() |
55
|
27 |
|
->scalarNode('query_parser_encoding') |
56
|
27 |
|
->defaultValue(LuceneManager::DEFAULT_QUERY_PARSER_ENCODING) |
57
|
27 |
|
->end() |
58
|
27 |
|
->end() |
59
|
27 |
|
->end(); |
60
|
|
|
|
61
|
27 |
|
return $treeBuilder; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
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: