I am trying to create an object oriented form generator. Please keep in mind that it will only be used by a few people in our company to solve a specific problem.
Currently, I come across two small reservations.
Item Creation Syntax
There are several approaches that I can take.
Setting up everything in the constructor. As a disadvantage, this can lead to inappropriate use of the constructor.
Input::create('text', 'name', array('maxlength' => 10));
Constraint constructor for entering and displaying only the most used attributes as methods (keep one method for setting the mass attribute)
Input::create('text')->name('name')->value('value')->attribute('max_length', 10);
Set each attribute as a method, either when creating a method for each attribute, or using the magic __call method, which will not lead to support for autocomplete in the IDE. And even now I can save the attribute method.
Input::create()->type('text')->name('name')->value('value')->max_length(10)->id('id');
At the moment, I think the second approach is the best, because it preserves the “good” things from both worlds. Since it still provides a way to do the abstract part of the work, because, for example, the required method will not only set the required attribute, but also mark this field for the verification object as necessary.
Code duplication with approach 2 and 3
Since there are attributes that can be used by each element, but also attributes that can be used by only 3 or 4 elements, for example. HTML5 form attribute.
Each element can inherit a basic element that has methods for attributes that are universal for each element (for example, name ). Partially used attributes can be solved using interfaces, but this leads to duplication of code, since they cannot contain the body of the method.
Traits would be a solution, but unfortunately I was stuck on PHP 5.3 with no upgradeability. This leaves me with either the implementation of the Mixin or Composition template, which again cannot lead to support for autocomplete. This will be partially mitigated by using the second approach.
So to my actual question:
Which approach might end up as the most appropriate? (Suitable as with minimal code duplication, reuse of solid code and ease of implementation)
I understand that this can very well generate answers based on opinions, so I apologize in advance if this happens.