bjori / mongo-php-transistor

A trait to save and load your objects in MongoDB
BSD 2-Clause "Simplified" License
28 stars 3 forks source link

split features #9

Open renanbr opened 8 years ago

renanbr commented 8 years ago

I've made some experiments with @alfsb, then this idea come from these experiences. Features could be splitted on traits, so users could pick which attach to their classes.

A full-featured persistable class sample:

class Document implements MongoDB\BSON\Persistable
{
    use Persistent; // base trait, it provides persistable methods implementation
    use CreatedField; // provides $_created and getCreated()
    use LastModifiedField; // provides $_lastModified and getLastModified()
    use AutoGeneratedId; // provides $_id and getId()
    // and others, such as atomic update

    /* ... */
}
bjori commented 8 years ago

I did originally think about something like that, but it seemed to be overly complicated to check if this or that functionality was enabled when serializing. And when adding new traits into the mix, the base trait would always have to be specifically told about it.

If you can come up with a way that seamlessly can support it, then I think that would be pretty cool!

renanbr commented 8 years ago

I've made an initial work at the split branch to try the concept out.

Important notes:

bjori commented 8 years ago

I think those tests already fail in the current branch, don't they? @jmikola told me they were going to remove support for atomic updates

jmikola commented 8 years ago

Correct. There are no plans to change the persistence spec or driver here. The ODS field will always injected into the bsonSerialize() return value if the class implements MongoDB\BSON\Persistable.

@derickr was actually just talking about removing the two ODS tests that we marked as XFAIL.