Creating an ORM for PHP and would like some input

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
m4rw3r
Forum Commoner
Posts: 33
Joined: Mon Aug 03, 2009 4:19 pm
Location: Sweden

Re: Creating an ORM for PHP and would like some input

Post by m4rw3r »

I'm starting the rewrite today, so I hope everything goes well and also makes it more flexible.
The large problem I've always had before is how to make the code builder more flexible (efficiency is of no concern, as it just compiles the mapper one time, then caches it),
so anyone having some experience with generating a large chunk of specialized code?

The code builder creates the mappers, which means that it needs to be flexible to be able to adapt to different circumstances.
One example is the i18n plugin I have some thoughts on, it would join a +"_lang" table which contains translated words and
then fetch the data from there, to make it appear to come from the same table. This means that the mapper must be able to
replace quite large chunks of code (creating the queries and saving the object (ie. two stages, one for the i18n data and the other
for the non-i18n data).

@Josh:
You mean the mapper should use a default descriptor which uses the Reflection API + the table structure to define the columns? (provided no special one was found)
That might be handy, but then it would be difficult to establish relations properly without following some rigorous naming standard.
(Also, it won't be good for the table generator, as the descriptor would contain insufficient data for table creation, but that might not always matter)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Creating an ORM for PHP and would like some input

Post by josh »

Table structure is sufficient, yes you would have to name things consistently ( unless you are going to manually subclass the mapper and provide a descriptor by hand. ) If you are repeating your fields and adding simplistic modules daily it doesnt make sense to keep repeating simple string fields, maybe if there were more complex relations manual descriptors would be more neccessary, having hte ability to override allows you to decide on a case per case basis tho.
User avatar
m4rw3r
Forum Commoner
Posts: 33
Joined: Mon Aug 03, 2009 4:19 pm
Location: Sweden

Re: Creating an ORM for PHP and would like some input

Post by m4rw3r »

I've created a github repository here: http://github.com/m4rw3r/RapidDataMapper/tree/master.

Currently it abstracts the database and provides result objects (it is a complete rewrite, but I'm copying some of the old code).

I'm working on the descriptors, but I'm getting close to where I would need some kind of flexible code builder, any ideas?
Because it will create class specific mappers (they extend a base mapper) which will contain specific code for saving/fetching/relations/etc. which makes it fast.
Post Reply