Some code might help. Suggest you read this:
https://laracasts.com/discuss/channels/general-discussion/guidelines-for-posting-on-laracastscom
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I currently have this setup: ConnectionInterface (XmlConnection or DbConnection). My data provider currently uses a XmlConnection but that may change.
XmlConnection can download many xml files with different content. That content must individually be proccessed and modified to be able to be displayed on my page and also be written in my own database. Therefore I would need something like this XmlTimes and XmlSpeeds and I might add more later (XmlConstruction, etc). If my provider changes to a Db then I would have DbTimes and DbSpeeds plus anything else that I would add later. These classes contain theodifications needed to make data consistent so I can write it to my database.
So when I build for example my TimesRepository all my ideas break the open closed principle.
ConnectionInterface is bind with XmlConnection
TimesRepository Construct with ConnectionInterface and an XmlTimes object.
If my provider changes to a DbConnection i then bind ConnectionInterface with DbConnection but then inside my TimesRepository I would have to change to a DbTimes object. therefore I break open closed principle.
How can I make it then SOLID?
My code:
<?php namespace App\Repositories\Traffic;
interface ConnectionInterface {
public function setSource($source);
function connect();
}
<?php namespace App\Repositories\Traffic;
class XmlConnection implements ConnectionInterface {
private $username, $password;
private $curlConn;
private $source = NULL;
public function __construct()
{
$this->username = env('XML_CONNECTION_USERNAME');
$this->password = env('XML_CONNECTION_PASSWORD');
$this->curlConn = curl_init();
}
public function setSource($source)
{
$this->source = $source;
}
public function connect()
{
if($this->source == NULL)
return 'Error';
$url = 'https://...';
curl_setopt($this->curlConn, CURLOPT_URL, $url . $this->source);
curl_setopt($this->curlConn, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curlConn, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->curlConn, CURLOPT_HEADER, 0);
curl_setopt($this->curlConn, CURLOPT_USERPWD, $this->username . ':' . $this->password);
$curlOut = curl_exec($this->curlConn);
curl_close($this->curlConn);
// file is gz archived
return gzdecode($curlOut);
}
}
Next I need to build a class that contains all the modifications I need for XmlTimesRepository (and of course for the other Repositories I would need) and then I guess I need another class TimesRepository which deals with the data after it was modified and does not know where the data came from XML or from a DB. This is where I am stuck!
Please or to participate in this conversation.