mardi 3 mai 2022

Recommendation on patterns/code structure (Laravel)

I wanted to ask for recommendations on what patterns or structure would you use in the following scenario.

I'm building a web app that it's basically a migrator that executes automatically everyday at a certain time and it takes data from a database then it does some processing and send it to and API.

The thing is that it does a lot of different migrations, so to make controllers readable and keep the single responsibility principle I have a lot of Controllers for each set of data that it takes from the database and then sends to the API. But at the same time I want to have only one point of entry to the whole process. So my idea would be something like this:

class AppController extends Controller{
    public function executeAllMigrations(){
        // Here I would like to start calling the methods from the others controllers and base on the response log some data so I would like to accomplish something like this:
        $response = call(firstController::class,'method'); 
        if($response){
                // do something
        }
        $response = call(secondController::class,'method'); 
        if($response){
                // do something
        }
        // And so on...
        // So the idea would be not to redirect to a different route but to get a response from a method controller
    }

Would you say that this structure don't make sense or in case it does, how would I do to make those calls and get the responses.

Maybe my setup doesn't make any sense at all and I would have to do something completly different so I will really appreciate all comments.

Aucun commentaire:

Enregistrer un commentaire