|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / a / home / dev2.destoffenstraat.com / app / Firebear / ImportExport / Model / Job / Strategy / |
Filename | /home/a/home/dev2.destoffenstraat.com/app/Firebear/ImportExport/Model/Job/Strategy/StrategyPool.php |
Size | 2.41 kb |
Permission | rw-rw-r-- |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 07-Nov-2022 06:44 |
Last accessed | 23-Aug-2025 10:32 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* @copyright: Copyright © 2021 Firebear Studio. All rights reserved.
* @author: Firebear Studio <fbeardev@gmail.com>
*/
namespace Firebear\ImportExport\Model\Job\Strategy;
use Magento\Framework\Exception\LocalizedException;
/**
* @api
*/
class StrategyPool implements StrategyPoolInterface
{
/**
* @var mixed[]
*/
protected $strategies = [];
/**
* @var StrategyInterface[]
*/
protected $strategiesInstances = [];
/**
* @var StrategyFactory
*/
protected $factory;
/**
* @param StrategyFactory $factory
* @param mixed[] $strategies
*/
public function __construct(
StrategyFactory $factory,
array $strategies = []
) {
$this->factory = $factory;
$this->strategies = $this->sort($strategies);
}
/**
* Retrieve strategies
*
* @return mixed[]
*/
public function getStrategies()
{
return $this->strategies;
}
/**
* Retrieve strategies instantiated
*
* @return StrategyInterface[]
* @throws LocalizedException
*/
public function getStrategiesInstances()
{
if ($this->strategiesInstances) {
return $this->strategiesInstances;
}
foreach ($this->strategies as $strategy) {
if (empty($strategy['class'])) {
throw new LocalizedException(__('The parameter "class" is missing. Set the "class" and try again.'));
}
if (empty($strategy['sortOrder'])) {
throw new LocalizedException(
__('The parameter "sortOrder" is missing. Set the "sortOrder" and try again.')
);
}
$this->strategiesInstances[] = $this->factory->create($strategy['class']);
}
return $this->strategiesInstances;
}
/**
* Sorting strategies according to sort order
*
* @param mixed[] $data
* @return mixed[]
*/
protected function sort(array $data)
{
usort($data, function (array $a, array $b) {
return $this->getSortOrder($a) <=> $this->getSortOrder($b);
});
return $data;
}
/**
* Retrieve sort order from array
*
* @param mixed[] $variable
* @return int
*/
protected function getSortOrder(array $variable)
{
return !empty($variable['sortOrder']) ? $variable['sortOrder'] : 0;
}
}
/**
* @copyright: Copyright © 2021 Firebear Studio. All rights reserved.
* @author: Firebear Studio <fbeardev@gmail.com>
*/
namespace Firebear\ImportExport\Model\Job\Strategy;
use Magento\Framework\Exception\LocalizedException;
/**
* @api
*/
class StrategyPool implements StrategyPoolInterface
{
/**
* @var mixed[]
*/
protected $strategies = [];
/**
* @var StrategyInterface[]
*/
protected $strategiesInstances = [];
/**
* @var StrategyFactory
*/
protected $factory;
/**
* @param StrategyFactory $factory
* @param mixed[] $strategies
*/
public function __construct(
StrategyFactory $factory,
array $strategies = []
) {
$this->factory = $factory;
$this->strategies = $this->sort($strategies);
}
/**
* Retrieve strategies
*
* @return mixed[]
*/
public function getStrategies()
{
return $this->strategies;
}
/**
* Retrieve strategies instantiated
*
* @return StrategyInterface[]
* @throws LocalizedException
*/
public function getStrategiesInstances()
{
if ($this->strategiesInstances) {
return $this->strategiesInstances;
}
foreach ($this->strategies as $strategy) {
if (empty($strategy['class'])) {
throw new LocalizedException(__('The parameter "class" is missing. Set the "class" and try again.'));
}
if (empty($strategy['sortOrder'])) {
throw new LocalizedException(
__('The parameter "sortOrder" is missing. Set the "sortOrder" and try again.')
);
}
$this->strategiesInstances[] = $this->factory->create($strategy['class']);
}
return $this->strategiesInstances;
}
/**
* Sorting strategies according to sort order
*
* @param mixed[] $data
* @return mixed[]
*/
protected function sort(array $data)
{
usort($data, function (array $a, array $b) {
return $this->getSortOrder($a) <=> $this->getSortOrder($b);
});
return $data;
}
/**
* Retrieve sort order from array
*
* @param mixed[] $variable
* @return int
*/
protected function getSortOrder(array $variable)
{
return !empty($variable['sortOrder']) ? $variable['sortOrder'] : 0;
}
}