Files
kupshop/bundles/KupShop/DropshipBundle/Util/TransferLocator.php
2025-08-02 16:30:27 +02:00

45 lines
918 B
PHP

<?php
namespace KupShop\DropshipBundle\Util;
use KupShop\DropshipBundle\Exception\TransferNotFoundException;
use KupShop\DropshipBundle\TransferInterface;
class TransferLocator
{
private $transfers;
public function __construct(iterable $transfers)
{
$this->transfers = $transfers;
}
public function getTypes(): array
{
return array_keys($this->getTransfers());
}
/**
* @return TransferInterface[]
*/
public function getTransfers(): array
{
$result = [];
foreach ($this->transfers as $transfer) {
$result[$transfer::getType()] = $transfer;
}
return $result;
}
public function getTransfer(string $type): TransferInterface
{
if ($transfer = $this->getTransfers()[$type] ?? null) {
return $transfer;
}
throw new TransferNotFoundException($type);
}
}