| 1 | <?php |
||
| 7 | abstract class AbstractFormatter implements FormatterInterface |
||
| 8 | { |
||
| 9 | /** @var FormatterInterface */ |
||
| 10 | protected $formatter; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * AbstractFormatter constructor. |
||
| 14 | * |
||
| 15 | * @param null|FormatterInterface $formatter |
||
| 16 | */ |
||
| 17 | 10 | public function __construct($formatter = null) |
|
| 18 | { |
||
| 19 | 10 | if (!$formatter instanceof FormatterInterface) { |
|
| 20 | 10 | $formatter = new NullFormatter(); |
|
| 21 | } |
||
| 22 | |||
| 23 | 10 | $this->setFormatter($formatter); |
|
| 24 | 10 | } |
|
| 25 | |||
| 26 | /** |
||
| 27 | * @param $value |
||
| 28 | * |
||
| 29 | * @return mixed |
||
| 30 | */ |
||
| 31 | abstract protected function getFormattedValue($value); |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @inheritdoc |
||
| 35 | */ |
||
| 36 | 8 | public function format($value) |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @param FormatterInterface $formatter |
||
| 47 | * |
||
| 48 | * @return AbstractFormatter |
||
| 49 | */ |
||
| 50 | 10 | public function setFormatter(FormatterInterface $formatter) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @return FormatterInterface |
||
| 59 | */ |
||
| 60 | 8 | public function getFormatter() |
|
| 64 | } |
||
| 65 |