| @@ 60-82 (lines=23) @@ | ||
| 57 | /** |
|
| 58 | * @inheritdoc |
|
| 59 | */ |
|
| 60 | public function getDecoder($name) |
|
| 61 | { |
|
| 62 | if (!array_key_exists($name, $this->decoders)) { |
|
| 63 | throw new \RuntimeException(sprintf("Decoder with name '%s' is not registered", $name)); |
|
| 64 | } |
|
| 65 | ||
| 66 | if ($this->decoders[$name] instanceof \Closure) { |
|
| 67 | $factory = $this->decoders[$name]; |
|
| 68 | $decoder = $factory(); |
|
| 69 | if (!$decoder instanceof DecoderInterface) { |
|
| 70 | throw new \LogicException(sprintf( |
|
| 71 | "Decoder '%s' should implement %s interface", |
|
| 72 | $name, |
|
| 73 | DecoderInterface::class |
|
| 74 | )); |
|
| 75 | } |
|
| 76 | ||
| 77 | $this->decoders[$name] = $decoder; |
|
| 78 | ||
| 79 | } |
|
| 80 | ||
| 81 | return $this->decoders[$name]; |
|
| 82 | } |
|
| 83 | ||
| 84 | /** |
|
| 85 | * @inheritdoc |
|
| @@ 104-125 (lines=22) @@ | ||
| 101 | /** |
|
| 102 | * @inheritdoc |
|
| 103 | */ |
|
| 104 | public function getEncoder($name) |
|
| 105 | { |
|
| 106 | if (!array_key_exists($name, $this->encoders)) { |
|
| 107 | throw new \RuntimeException(sprintf("Encoder with name '%s' is not registered", $name)); |
|
| 108 | } |
|
| 109 | ||
| 110 | if ($this->encoders[$name] instanceof \Closure) { |
|
| 111 | $factory = $this->encoders[$name]; |
|
| 112 | $encoder = $factory(); |
|
| 113 | if (!$encoder instanceof EncoderInterface) { |
|
| 114 | throw new \LogicException(sprintf( |
|
| 115 | "Encoder '%s' should implement %s interface", |
|
| 116 | $name, |
|
| 117 | EncoderInterface::class |
|
| 118 | )); |
|
| 119 | } |
|
| 120 | ||
| 121 | $this->encoders[$name] = $encoder; |
|
| 122 | } |
|
| 123 | ||
| 124 | return $this->encoders[$name]; |
|
| 125 | } |
|
| 126 | } |
|