Factory Method
This commit is contained in:
34
src/Pattern/Creational/FactoryMethod/PaymentHelper.php
Normal file
34
src/Pattern/Creational/FactoryMethod/PaymentHelper.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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")
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user