-
Notifications
You must be signed in to change notification settings - Fork 46
Make attachment model classes dynamic #76
base: master
Are you sure you want to change the base?
Conversation
6ffc956
to
fe84082
Compare
fe84082
to
3db983d
Compare
*/ | ||
public function __construct($attachmentModelClassName) | ||
{ | ||
$this->attachmentModelClassName = $attachmentModelClassName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get model class from config directly, without requirement to pass it into constructor.
Also let's omit "name" suffix and attachment prefix, we already in DetachAttachment
class context. The repetition of context is mostly redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get model class from config directly, without requirement to pass it into constructor.
Why would you create a tight coupling between the handlers, which are small and single-purpose classes, and the config helper? There's no need for them to know about the framework and its helpers. Injecting the model class makes them less dependent.
Also let's omit "name" suffix and attachment prefix, we already in DetachAttachment class context. The repetition of context is mostly redundant.
Why not be as explicit as possible? Is there a cost to having a slightly longer variable/property name?
$modelClassName = $this->app['config']->get('nova.froala-field.attachment_model'); | ||
|
||
/** @var Model $model */ | ||
$model = new $modelClassName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract get table of class string to the own method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't sound very DRY. Any specific reason for introducing code duplication?
f7d9939
to
ef40777
Compare
In my current project I work with UUID's for all my models. I want the Froala attachments to also use UUID's instead of integers. To do this I need to extend the models and set their
$keyType
property tostring
. This currently isn't possible so I've made the model classes dynamic so you can easily swap them with extensions.