Rules
1 month ago
CachedWordInflector.php
1 month ago
GenericLanguageInflectorFactory.php
1 month ago
Inflector.php
1 month ago
InflectorFactory.php
1 month ago
Language.php
1 month ago
LanguageInflectorFactory.php
1 month ago
NoopWordInflector.php
1 month ago
RulesetInflector.php
1 month ago
WordInflector.php
1 month ago
GenericLanguageInflectorFactory.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace IAWPSCOPED\Doctrine\Inflector; |
| 5 | |
| 6 | use IAWPSCOPED\Doctrine\Inflector\Rules\Ruleset; |
| 7 | use function array_unshift; |
| 8 | /** @internal */ |
| 9 | abstract class GenericLanguageInflectorFactory implements LanguageInflectorFactory |
| 10 | { |
| 11 | /** @var Ruleset[] */ |
| 12 | private $singularRulesets = []; |
| 13 | /** @var Ruleset[] */ |
| 14 | private $pluralRulesets = []; |
| 15 | public final function __construct() |
| 16 | { |
| 17 | $this->singularRulesets[] = $this->getSingularRuleset(); |
| 18 | $this->pluralRulesets[] = $this->getPluralRuleset(); |
| 19 | } |
| 20 | public final function build() : Inflector |
| 21 | { |
| 22 | return new Inflector(new CachedWordInflector(new RulesetInflector(...$this->singularRulesets)), new CachedWordInflector(new RulesetInflector(...$this->pluralRulesets))); |
| 23 | } |
| 24 | public final function withSingularRules(?Ruleset $singularRules, bool $reset = \false) : LanguageInflectorFactory |
| 25 | { |
| 26 | if ($reset) { |
| 27 | $this->singularRulesets = []; |
| 28 | } |
| 29 | if ($singularRules instanceof Ruleset) { |
| 30 | array_unshift($this->singularRulesets, $singularRules); |
| 31 | } |
| 32 | return $this; |
| 33 | } |
| 34 | public final function withPluralRules(?Ruleset $pluralRules, bool $reset = \false) : LanguageInflectorFactory |
| 35 | { |
| 36 | if ($reset) { |
| 37 | $this->pluralRulesets = []; |
| 38 | } |
| 39 | if ($pluralRules instanceof Ruleset) { |
| 40 | array_unshift($this->pluralRulesets, $pluralRules); |
| 41 | } |
| 42 | return $this; |
| 43 | } |
| 44 | protected abstract function getSingularRuleset() : Ruleset; |
| 45 | protected abstract function getPluralRuleset() : Ruleset; |
| 46 | } |
| 47 |