Hi,
I have an application design question.
Lets say I have multiple providers, that will send me delivery reports. I want to store the raw data (which differ from each provider) in a provider specific mysql table and transform it into a universal delivery report for the rest of my system. Without having to add the dependencies in the provider classes.
I was thinking something like this
class BaseDeliveryReport implements DeliveryReportInterface
{
protected $repo;
public function __construct(DeliveryReportRepositoryInterface $repo)
{
$this->repo = $repo;
}
public function create($attributes)
{
// Store delivery report etc...
}
// ...
}
My thought was to then do this:
class Provider1DeliveryReport extends BaseDeliveryReport
{
protected function storeRawData($attributes) {
// Provider specific stuff here
}
public function create($attributes)
{
$this->storeRawData($attributes);
parent::create($attributes);
}
}
$data = Input::all(); // or something...
$deliveryReport = new Provider1DeliveryReport();
$deliveryReport->create($data);
From my understanding I cannot do this, and I wonder how I can solve this without having to repeat the dependency injection in each providers constructor.
Thanks :)
The parent's constructor is not automatically fired when extending it. So the repo is not setup when you do
new Provider1DeliveryReport();
You can solve it by adding parent::__construct()
to you Provider1DeliveryReport::__construct()
but that's the same amount of work as injecting the repo.
Maybe somebody else has a great idea.
Thanks for your reply zenry.
Actually, the only way I get this working is to do like this on all provider classes:
public function __construct(DeliveryReportRepositoryInterface $repo)
{
parent::__construct($repo);
}
Hopefully some skilled guy or gal out there has a solution to this :D
Thanks anyway!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community