I'm using Laravel 5.2 to build an abstract system. When a customer needs some specific implementation, I need to override some parts of the code.
What I'm thinking is something like this scenario:
A Controller depends on some custom Request (concrete) by default. When a customer asks me another business rule, I'd have to extend this custom Request and bind this child implementation to the parent. Do something like this on my Provider:
$this->app->bind(ParentImpl::class, ChildImpl::class);
Talking about software architecture concepts, can I do it? Is it correct?
[EDIT]
A concrete example, I have an action that uses a Request like this:
class SomeController extends Controller
{
public function someAction(ParentRequest $request)
{
# perform action
}
}
My Request have some business validation logic:
class ParentRequest extends Request
{
public function rules()
{
return [
'a_field' => 'required',
'b_field' => 'max:100'
];
}
}
Now everything works, my default system logic is ok! But my software is a base to other projects, we will use it via composer and at the final projects just the specific code will belong to app path.
When a customer ask for some modification of business logic we'll need to override the old. My question is: is it correct? Can I, conceptually talking, do something like this code below?
class ChildRequest extends ParentRequest
{
public function rules()
{
return [
'a_field' => '',
'b_field' => 'max:255'
];
}
}
And then, bind it to override all dependencies of the project:
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(ParentImpl::class, ChildImpl::class);
}
}