| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Doctrine\Inflector\Rules; |
| 6 |
|
| 7 |
use Doctrine\Inflector\WordInflector; |
| 8 |
|
| 9 |
use function preg_replace; |
| 10 |
|
| 11 |
final class Transformation implements WordInflector |
| 12 |
{ |
| 13 |
|
| 14 |
private $pattern; |
| 15 |
|
| 16 |
|
| 17 |
private $replacement; |
| 18 |
|
| 19 |
public function __construct(Pattern $pattern, string $replacement) |
| 20 |
{ |
| 21 |
$this->pattern = $pattern; |
| 22 |
$this->replacement = $replacement; |
| 23 |
} |
| 24 |
|
| 25 |
public function getPattern(): Pattern |
| 26 |
{ |
| 27 |
return $this->pattern; |
| 28 |
} |
| 29 |
|
| 30 |
public function getReplacement(): string |
| 31 |
{ |
| 32 |
return $this->replacement; |
| 33 |
} |
| 34 |
|
| 35 |
public function inflect(string $word): string |
| 36 |
{ |
| 37 |
return (string) preg_replace($this->pattern->getRegex(), $this->replacement, $word); |
| 38 |
} |
| 39 |
} |