English
1 month ago
Esperanto
1 month ago
French
1 month ago
Italian
1 month ago
NorwegianBokmal
1 month ago
Portuguese
1 month ago
Spanish
1 month ago
Turkish
1 month ago
Pattern.php
1 month ago
Patterns.php
1 month ago
Ruleset.php
1 month ago
Substitution.php
1 month ago
Substitutions.php
1 month ago
Transformation.php
1 month ago
Transformations.php
1 month ago
Word.php
1 month ago
Transformation.php
33 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace IAWPSCOPED\Doctrine\Inflector\Rules; |
| 5 | |
| 6 | use IAWPSCOPED\Doctrine\Inflector\WordInflector; |
| 7 | use function preg_replace; |
| 8 | /** @internal */ |
| 9 | final class Transformation implements WordInflector |
| 10 | { |
| 11 | /** @var Pattern */ |
| 12 | private $pattern; |
| 13 | /** @var string */ |
| 14 | private $replacement; |
| 15 | public function __construct(Pattern $pattern, string $replacement) |
| 16 | { |
| 17 | $this->pattern = $pattern; |
| 18 | $this->replacement = $replacement; |
| 19 | } |
| 20 | public function getPattern() : Pattern |
| 21 | { |
| 22 | return $this->pattern; |
| 23 | } |
| 24 | public function getReplacement() : string |
| 25 | { |
| 26 | return $this->replacement; |
| 27 | } |
| 28 | public function inflect(string $word) : string |
| 29 | { |
| 30 | return (string) preg_replace($this->pattern->getRegex(), $this->replacement, $word); |
| 31 | } |
| 32 | } |
| 33 |