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