V
V
vitaly_742020-05-07 09:51:25
PHP
vitaly_74, 2020-05-07 09:51:25

What is the best way to transfer the config along the “chain of responsibilities”?

new PaymentOf(
    new ConcreatePaymentSystem(
        new CardForm(
            $_POST
        )
    )
);

Now I am writing a small library to connect payment systems (it has proven itself well in production). But here's the question. in PaymentOf you need to pass the database config to write values. in ConcreatePaymentSystem, you need to pass the config for authorizing the site on the side of the payment system (the so-called secret and public keys). How to do it elegantly and well. Here is an example of a config that organized

$config = new Config(
[
    'secret' => [
        'secret_key' => '',
        'auth_key' => '',
    ],
    'db' => [
        'db_host' => '', //with db
        'db_name' => '', //with db
        'username' => '', //with db
        'password' => '', //with db
        'db_type' => 'mysql' //with db
    ],
    'urls'=>[
        'callback_url'=>'',//default
        'after_payment_url'=>'', //default
        'fail_url'=>'', //default
        'success_url'=>'', //default
    ]
]);

I also pursue the goal of simplicity, convenience and extensibility. Also, I would like to make sure that the beginner figured out how to work with it. thanks in advance for the replies.

ps I know about the existence of analogues - but they do not suit me.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question