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

cloud4bpm's avatar

Use of SOLID principles for creating custom PHP Providers of Services Classes

Hi,

I'm creating some classes accessing certain APIs through PHP code, but I want my code to be clear and, if possible, SOLID. But I find the following questions:

  1. For example, if I create a class that allows me access to an API and get data in various formats JSON, XML, CSV, etc. It would be best to create an abstract class and individual part of each provider is implemented through a child class. I'm using this aproximation right now.

  2. Use public API interfaces for general Provider functionality.

  3. Use traits for the common part (eg, methods that are implemented in the same way in each individual Provider).

But the problem comes when not all APIs (eg Authentication, Conversors, ...) might not have the same amount of common API methods. For example a new method, but which, by its nature, is not possible pull-up to the Abstract Provider class.

What strategy would you use if you have to target potential providers of certain APIs if not all meet the same interface but some methods implemented more than others? Extract the base methods on the Abstract Provider class and using Segregation Interfaces?

Thanks in advance.

0 likes
0 replies

Please or to participate in this conversation.