Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mikelovely's avatar

Which Design Pattern should I use here

I'm not too confident with Design Patterns but trying a lot harder these days to make conscious use of them.

I have an api that will perform a series to steps but the ultimate goal is do get records from a db, put them in to a spreadsheet, and email that to an address provided by the client.

Here it is broken in to steps:

  1. Get all records from db using params provided by client
  2. Create either a csv or excel populated with results of the query
  3. Create password protected zip file containing the sheet
  4. Send sheet and email address info to another api which will actually work out sending the email

In the future I may need to:

  • Support exporting from other tables
  • If exporting from other tables, the headers of the spreadsheet will need to be different
  • Sending the email in other formats eg: json

At the moment I am just going through the step one at a time in the controller. But if I need to account for the future scenarios listed above then I can see it getting extremely bloated.

It's not Chain Of Responsibility. I don't think it's a Factory. I'm looking at https://refactoring.guru/design-patterns/php but I can't see a suitable pattern.

0 likes
1 reply
bugsysha's avatar

You are right. It is none of those which you've mentioned. You need multiple patterns to achieve this which might include ones you've mentioned.

From controller prepare data and pass it to some class which will be responsible to whole that flow. Then within that class delegate to separate classes for each of those concerns.

Please or to participate in this conversation.