| @@ 22-57 (lines=36) @@ | ||
| 19 | use Gpupo\CommonSchema\TranslatorInterface; |
|
| 20 | use Gpupo\CommonSdk\Traits\LoadTrait; |
|
| 21 | ||
| 22 | final class Translator extends AbstractTranslator implements TranslatorInterface |
|
| 23 | { |
|
| 24 | use LoadTrait; |
|
| 25 | ||
| 26 | private function loadMap($name) |
|
| 27 | { |
|
| 28 | $file = __DIR__.'/map/translate.'.$name.'.map.php'; |
|
| 29 | $method = 'get'.ucfirst($name); |
|
| 30 | ||
| 31 | return $this->loadArrayFromFile($file, [$name => $this->$method()]); |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * {@inheritdoc} |
|
| 36 | */ |
|
| 37 | public function translateTo() |
|
| 38 | { |
|
| 39 | if (!$this->getNative() instanceof Order) { |
|
| 40 | throw new \Exception('Order missed!'); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $this->factoryOutputCollection($this->loadMap('native')); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * {@inheritdoc} |
|
| 48 | */ |
|
| 49 | public function translateFrom() |
|
| 50 | { |
|
| 51 | if (!$this->getForeign() instanceof TranslatorDataCollection) { |
|
| 52 | throw new \Exception('Foreign missed!'); |
|
| 53 | } |
|
| 54 | ||
| 55 | return new Order($this->loadMap('foreign')); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| @@ 22-58 (lines=37) @@ | ||
| 19 | use Gpupo\CommonSchema\TranslatorInterface; |
|
| 20 | use Gpupo\CommonSdk\Traits\LoadTrait; |
|
| 21 | ||
| 22 | final class Translator extends AbstractTranslator implements TranslatorInterface |
|
| 23 | { |
|
| 24 | use LoadTrait; |
|
| 25 | ||
| 26 | private function loadMap($name) |
|
| 27 | { |
|
| 28 | $file = __DIR__.'/map/translate.'.$name.'.map.php'; |
|
| 29 | $method = 'get'.ucfirst($name); |
|
| 30 | $pars = [$name => $this->$method()]; |
|
| 31 | ||
| 32 | return $this->loadArrayFromFile($file, $pars); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * {@inheritdoc} |
|
| 37 | */ |
|
| 38 | public function translateTo() |
|
| 39 | { |
|
| 40 | if (!$this->getNative() instanceof Product) { |
|
| 41 | throw new \Exception('Product missed!'); |
|
| 42 | } |
|
| 43 | ||
| 44 | return $this->factoryOutputCollection($this->loadMap('native')); |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public function translateFrom() |
|
| 51 | { |
|
| 52 | if (!$this->getForeign() instanceof TranslatorDataCollection) { |
|
| 53 | throw new \Exception('Foreign missed!'); |
|
| 54 | } |
|
| 55 | ||
| 56 | return new Product($this->loadMap('foreign')); |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||