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
CachedWordInflector.php
22 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace IAWPSCOPED\Doctrine\Inflector; |
| 5 | |
| 6 | /** @internal */ |
| 7 | class CachedWordInflector implements WordInflector |
| 8 | { |
| 9 | /** @var WordInflector */ |
| 10 | private $wordInflector; |
| 11 | /** @var string[] */ |
| 12 | private $cache = []; |
| 13 | public function __construct(WordInflector $wordInflector) |
| 14 | { |
| 15 | $this->wordInflector = $wordInflector; |
| 16 | } |
| 17 | public function inflect(string $word) : string |
| 18 | { |
| 19 | return $this->cache[$word] ?? ($this->cache[$word] = $this->wordInflector->inflect($word)); |
| 20 | } |
| 21 | } |
| 22 |