|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Inflector; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Inflector\Rules\Irregular; |
|
8
|
|
|
use Doctrine\Inflector\Rules\Plural; |
|
9
|
|
|
use Doctrine\Inflector\Rules\Rules; |
|
10
|
|
|
use Doctrine\Inflector\Rules\Ruleset; |
|
11
|
|
|
use Doctrine\Inflector\Rules\Singular; |
|
12
|
|
|
use Doctrine\Inflector\Rules\Uninflected; |
|
13
|
|
|
|
|
14
|
|
|
class InflectorFactory |
|
15
|
|
|
{ |
|
16
|
529 |
|
public function createInflector( |
|
17
|
|
|
?Ruleset $singularRuleset = null, |
|
18
|
|
|
?Ruleset $pluralRuleset = null |
|
19
|
|
|
) : Inflector { |
|
20
|
529 |
|
return new Inflector( |
|
21
|
529 |
|
new CacheRulesetInflector(new RulesetInflector( |
|
22
|
529 |
|
$singularRuleset ?? $this->createSingularRuleset() |
|
23
|
|
|
)), |
|
24
|
529 |
|
new CacheRulesetInflector(new RulesetInflector( |
|
25
|
529 |
|
$pluralRuleset ?? $this->createPluralRuleset() |
|
26
|
|
|
)) |
|
27
|
|
|
); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
529 |
|
public function createSingularRuleset( |
|
31
|
|
|
?Rules $rules = null, |
|
32
|
|
|
?Uninflected $uninflected = null, |
|
33
|
|
|
?Irregular $irregular = null, |
|
34
|
|
|
?Irregular $pluralIrregular = null |
|
35
|
|
|
) : Ruleset { |
|
36
|
529 |
|
$rules = $rules ?? new Rules(...Singular::getDefaultRules()); |
|
37
|
529 |
|
$uninflected = $uninflected ?? new Uninflected(...Singular::getUninflectedWords()); |
|
38
|
529 |
|
$irregular = $irregular ?? new Irregular(...Singular::getIrregularRules()); |
|
39
|
529 |
|
$pluralIrregular = $pluralIrregular ?? new Irregular(...Plural::getIrregularRules()); |
|
40
|
|
|
|
|
41
|
|
|
$singularUninflected = new Uninflected(...(static function () use ($uninflected) : iterable { |
|
42
|
529 |
|
yield from $uninflected->getWords(); |
|
43
|
529 |
|
yield from Uninflected::getDefaultWords(); |
|
44
|
529 |
|
})()); |
|
45
|
|
|
|
|
46
|
|
|
$singularIrregular = new Irregular(...(static function () use ($irregular, $pluralIrregular) : iterable { |
|
47
|
529 |
|
yield from $irregular->getRules(); |
|
48
|
529 |
|
yield from $pluralIrregular->getFlippedRules(); |
|
49
|
529 |
|
})()); |
|
50
|
|
|
|
|
51
|
529 |
|
return new Ruleset($rules, $singularUninflected, $singularIrregular); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
529 |
|
public function createPluralRuleset( |
|
55
|
|
|
?Rules $rules = null, |
|
56
|
|
|
?Uninflected $uninflected = null, |
|
57
|
|
|
?Irregular $irregular = null |
|
58
|
|
|
) : Ruleset { |
|
59
|
529 |
|
$rules = $rules ?? new Rules(...Plural::getDefaultRules()); |
|
60
|
529 |
|
$uninflected = $uninflected ?? new Uninflected(...Plural::getUninflectedWords()); |
|
61
|
529 |
|
$irregular = $irregular ?? new Irregular(...Plural::getIrregularRules()); |
|
62
|
|
|
|
|
63
|
|
|
$pluralUninflected = new Uninflected(...(static function () use ($uninflected) : iterable { |
|
64
|
529 |
|
yield from $uninflected->getWords(); |
|
65
|
529 |
|
yield from Uninflected::getDefaultWords(); |
|
66
|
529 |
|
})()); |
|
67
|
|
|
|
|
68
|
529 |
|
return new Ruleset($rules, $pluralUninflected, $irregular); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|