| 1 | <?php |
||
| 15 | trait IdFactoryDecoratorTrait |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var IdFactoryInterface |
||
| 19 | */ |
||
| 20 | private $decoratedFactory; |
||
| 21 | |||
| 22 | public function __construct(IdFactoryInterface $decoratedFactory = null) |
||
| 26 | |||
| 27 | public function createId(string $raw, \DateTimeInterface $atDate = null): IdInterface |
||
| 28 | { |
||
| 29 | try { |
||
| 30 | return $this->createNewInstance($raw, $atDate); |
||
| 31 | } catch (Exception $e) { |
||
| 32 | return $this->decoratedFactory->createId($raw, $atDate); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | abstract protected function createNewInstance(string $raw, \DateTimeInterface $atDate = null): IdInterface; |
||
| 37 | } |
||
| 38 |