Open dereuromark opened 4 years ago
Immutable first could go into the direction of
class ItemObject {
/**
* @var string
*/
protected $name;
/**
* @param array $fields
*/
public function __construct(array $fields = []) {
foreach ($fields as $field => $value) {
$this->$field = $value;
}
}
/**
* @return string
*/
public function getName(): string {
return $this->name;
}
/**
* Only exists for nullable properties.
*
* @return bool
*/
public function hasName(): bool {
return $this->name !== null;
}
}
Maybe Object
should be the suffix here to avoid clashing with Entity names, as they don't have any suffix in the Cake world right now.
Should this be a bake command maybe even?
bin/cake bake object Item field:type,field_other:type_other|null,...
Besides the useful and always regeneratable DTOs, I also saw sometimes the need for some simple standalone objects that are also customizable on some of the properties and behavior. Both for plugins or project level.
So what if we could
Similar to bake a migration, one would define fields as
on that CLI call
|null
indicates optional field.Alternatively, we could also allow/keep a
vo.xml
file in config, or allow this as input param to easily regenerate if the need arises.A result could be:
It could NOT have
BUT on the other side
If we include this there should be the option to include this as require-dev dependency on other plugins, so they can easily generate those for plugins as well, using e.g.
or alike.
// @asaliev would do you think?