gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

Code generator for models #777

Closed flip111 closed 4 years ago

flip111 commented 4 years ago

I've been thinking about this idea for a while now but i wanted to discuss it first before a possible implementation. It would be nice if there were a command to generate a PHP class for a type of bean. In this php class there can be properties, getters and setters. I would use this feature myself and i can also build it.

gabordemooij commented 4 years ago

You don't need that, you can access the bean through the model ($this->bean). This has been done to avoid code generation. ;-)

flip111 commented 4 years ago

I mean to generate models https://www.redbeanphp.com/index.php?p=/models like doctrine does it https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/tools.html#entity-generation

it's useful as stub and to have more type checking. It can also in help with serialization

gabordemooij commented 4 years ago

That approach is more for Doctrine. RedBeanPHP tries to follow the dynamic nature of PHP. You're welcome to write a plug-in though.

flip111 commented 4 years ago

What do you mean with the dynamic nature of PHP ?

gabordemooij commented 4 years ago

It's dynamically typed. It can convert stuff on-the-fly: '2' + 1 = 3 etc. This makes sense because it's an interpreter, so there is no compile-time check for types (like in Java - that is one of the benefits of types right? to have a compiler check those errors before runtime). It also allows you to write code quicker and in a less verbose way (because the interpreter is smart enough to cast values from one type to another). The downside is that you can have type-errors, however I prefer those to the verbosity (type definitions, explicit casts) and clunkyness (compilers, linting etc) of types. On the other hand, if I really need to do project where strong types can make a real difference I just use a different language, another (better?) tool for the job.

flip111 commented 4 years ago

I don't see the relation between on-the-fly schema creation and dynamic typing. IMO they don't need to be both there at the same time but are orthogonal.

gabordemooij commented 4 years ago

Feel free to write a plugin.

gabordemooij commented 4 years ago

Closing this issue because it has been decided to offer this functionality as a plug-in, not in the core of RedBeanPHP.