diff --git a/Api/ExportInterface.php b/Api/ExportInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..43e82e25513d1ae41796654d6bcb49d9807bb4fe --- /dev/null +++ b/Api/ExportInterface.php @@ -0,0 +1,16 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Api; + +use Firegento\ContentProvisioning\Api\Data\EntryInterface; + +interface ExportInterface +{ + /** + * @param StrategyInterface $strategy + * @param EntryInterface $entry + * @return void + */ + public function execute(StrategyInterface $strategy, EntryInterface $entry): void; +} \ No newline at end of file diff --git a/Api/StrategyInterface.php b/Api/StrategyInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..9fb3a23970a08c921045b69bfe9793ef40c1c2c5 --- /dev/null +++ b/Api/StrategyInterface.php @@ -0,0 +1,12 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Api; + +interface StrategyInterface +{ + /** + * @return string + */ + public function getTargetPath(): string; +} \ No newline at end of file diff --git a/Api/StrategyProviderInterface.php b/Api/StrategyProviderInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..1e1e9fd3c2d9a8be41415c3576955b064166cd94 --- /dev/null +++ b/Api/StrategyProviderInterface.php @@ -0,0 +1,17 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Api; + +use Magento\Framework\Exception\NotFoundException; + +interface StrategyProviderInterface +{ + /** + * @param string $strategyCode + * @return StrategyInterface + * + * @throws NotFoundException + */ + public function get(string $strategyCode): StrategyInterface; +} \ No newline at end of file diff --git a/Model/Strategy/ExportToModule.php b/Model/Strategy/ExportToModule.php new file mode 100644 index 0000000000000000000000000000000000000000..05e6ae5640c1c04c2549cd56e12889fb5e7cc7f4 --- /dev/null +++ b/Model/Strategy/ExportToModule.php @@ -0,0 +1,18 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Model\Strategy; + +use Firegento\ContentProvisioning\Api\StrategyInterface; + +class ExportToModule implements StrategyInterface +{ + + /** + * @return string + */ + public function getTargetPath(): string + { + // TODO: Implement getTargetPath() method. + } +} \ No newline at end of file diff --git a/Model/Strategy/ExportToVar.php b/Model/Strategy/ExportToVar.php new file mode 100644 index 0000000000000000000000000000000000000000..ea91dd43875eb5fe88435011fcdaebef8813a768 --- /dev/null +++ b/Model/Strategy/ExportToVar.php @@ -0,0 +1,18 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Model\Strategy; + +use Firegento\ContentProvisioning\Api\StrategyInterface; + +class ExportToVar implements StrategyInterface +{ + + /** + * @return string + */ + public function getTargetPath(): string + { + // TODO: Implement getTargetPath() method. + } +} \ No newline at end of file diff --git a/Model/Strategy/Provider.php b/Model/Strategy/Provider.php new file mode 100644 index 0000000000000000000000000000000000000000..d407feb3e1d62b1fa72ba44a2c469f0fa46fc224 --- /dev/null +++ b/Model/Strategy/Provider.php @@ -0,0 +1,42 @@ +<?php +declare(strict_types=1); + +namespace Firegento\ContentProvisioning\Model\Strategy; + +use Firegento\ContentProvisioning\Api\StrategyInterface; +use Firegento\ContentProvisioning\Api\StrategyProviderInterface; +use Magento\Framework\Exception\NotFoundException; + +class Provider implements StrategyProviderInterface +{ + /** + * @var array|StrategyInterface[] + */ + private $strategies; + + /** + * Provider constructor. + * @param StrategyInterface[] $strategies + */ + public function __construct(array $strategies) + { + $this->strategies = $strategies; + } + + /** + * @param string $strategyCode + * @return StrategyInterface + * + * @throws NotFoundException + */ + public function get(string $strategyCode): StrategyInterface + { + $strategy = $this->strategies[$strategyCode] ?? null; + + if (!$strategy) { + throw new NotFoundException(__('Strategy %s not found.', $strategyCode)); + } + + return $strategy; + } +} \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml index 18cd8dfb61440fbecee1bc019f966df55386427c..9442de59a3b6c33e4e2a4d5eed0e4c1da3ee5c9f 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -105,4 +105,24 @@ </argument> </arguments> </type> + + <preference + for="Firegento\ContentProvisioning\Api\StrategyProviderInterface" + type="Firegento\ContentProvisioning\Model\Strategy\Provider" + /> + + <preference + for="Firegento\ContentProvisioning\Api\ExportInterface" + type="Firegento\ContentProvisioning\Model\Command\ExportEntry" + /> + + <type name="Firegento\ContentProvisioning\Model\Strategy\Provider"> + <arguments> + <argument name="strategies" xsi:type="array"> + <item name="export_to_module" xsi:type="object">Firegento\ContentProvisioning\Model\Strategy\ExportToModule</item> + <item name="export_to_var" xsi:type="object">Firegento\ContentProvisioning\Model\Strategy\ExportToVar</item> + </argument> + </arguments> + </type> + </config>