M
M
Maxim Kovalev2019-07-04 18:27:20
PHP
Maxim Kovalev, 2019-07-04 18:27:20

There is a class (service) to which it is necessary to transfer the validated configuration. What is the best way to do it?

There is a service that works with two APIs. The data comes to the service from a web form. The form has its own class that can parse a post request into an object. Form - web level. Service - the level of business logic. It is necessary to provide for the possibility to use the same service from the console (for example). Therefore, you cannot directly pass the form as a parameter to it. How to correctly swipe the form in the configuration for the service? Is there any best practice for this?
PS: sorry for some confusion of the question.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2019-07-04
@ThunderCat

The form has its own class that can parse a post request into an object.
Is it essentially a DTO object? Pass DTO, if through the console - serialize and base64encode, in the controller of the console application already accept the parameter, convert it back and already feed it to the object of work with api.

4
4iloveg, 2019-07-04
@4iloveg

In the class, make one method that receives data from the form and another method - from the console.

A
Alexander Kubintsev, 2019-07-08
@akubintsev

I will duplicate Evgeny Dobryansky 's comment : "Make a class with parameters for the service, and who and how creates an object of this class for the service is not important"
The essence of the problem comes down to abstracting business logic from the method of obtaining data.
You can think of this as an adapter, which in one case is a controller that receives a web form. In the other, a console application command.
Whatever it was, you should not fill your head with patterns in this case, since there will not be many ways to get information at the input of the business logic one way or another. Well, what else can you add? API method out?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question