design-patterns/src/Pattern/Creational/FactoryMethod/PaymentHelper.php
2025-07-03 19:35:54 +03:00

35 lines
818 B
PHP

<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-03
* @time: 18:04
*/
declare(strict_types = 1);
namespace Pattern\Creational\FactoryMethod;
use RuntimeException;
class PaymentHelper
{
/**
* @param string $paymentType
*
* @return PaymentFactoryInterface
*/
public static function getPaymentFactory(string $paymentType): PaymentFactoryInterface
{
return match ($paymentType) {
'privat' => new PrivatPaymentFactory(),
'raiffeisen' => new RaiffeisenPaymentFactory(),
'ing' => new IngPaymentFactory(),
'otp' => new OtpPaymentFactory(),
'cash' => new CashPaymentFactory(),
default => throw new RuntimeException("Payment type '{$paymentType}' is unknown")
};
}
}