Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Doctrine\Inflector;
6
 
7
use Doctrine\Inflector\Rules\Ruleset;
8
 
9
use function array_unshift;
10
 
11
abstract class GenericLanguageInflectorFactory implements LanguageInflectorFactory
12
{
13
    /** @var Ruleset[] */
14
    private $singularRulesets = [];
15
 
16
    /** @var Ruleset[] */
17
    private $pluralRulesets = [];
18
 
19
    final public function __construct()
20
    {
21
        $this->singularRulesets[] = $this->getSingularRuleset();
22
        $this->pluralRulesets[]   = $this->getPluralRuleset();
23
    }
24
 
25
    final public function build(): Inflector
26
    {
27
        return new Inflector(
28
            new CachedWordInflector(new RulesetInflector(
29
                ...$this->singularRulesets
30
            )),
31
            new CachedWordInflector(new RulesetInflector(
32
                ...$this->pluralRulesets
33
            ))
34
        );
35
    }
36
 
37
    final public function withSingularRules(?Ruleset $singularRules, bool $reset = false): LanguageInflectorFactory
38
    {
39
        if ($reset) {
40
            $this->singularRulesets = [];
41
        }
42
 
43
        if ($singularRules instanceof Ruleset) {
44
            array_unshift($this->singularRulesets, $singularRules);
45
        }
46
 
47
        return $this;
48
    }
49
 
50
    final public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): LanguageInflectorFactory
51
    {
52
        if ($reset) {
53
            $this->pluralRulesets = [];
54
        }
55
 
56
        if ($pluralRules instanceof Ruleset) {
57
            array_unshift($this->pluralRulesets, $pluralRules);
58
        }
59
 
60
        return $this;
61
    }
62
 
63
    abstract protected function getSingularRuleset(): Ruleset;
64
 
65
    abstract protected function getPluralRuleset(): Ruleset;
66
}