dbv
dbv copied to clipboard
Callback hooks
Version 2.0 should allow developers to hook into the revision process at any stage. DBV should be an event emitter that hooks can listen on for events such as "revision.before", "revision.after", etc, using a syntax along these lines:
$dbv->on('revision.executed', [callable]);
I've actually stripped this capability down before launching, because I wanted to brush it off a bit. I've been using it to call a PHP script that removed some cache files after each revision script was executed and someone just coincidentally requested this feature, so I'm adding it to the 2.0 milestone.
Would callback hooks be a way to provide initial data to schema objects, or would that be a separate issue?
No no, callback hooks would be a way to execute arbitrary code each time something happens in DBV. For example, each time a revision script gets executed, remove some cache file from your projects. If you want to provide initial data for a table, you have two options:
- Create a revision script for each table with all the INSERT statements, and place them in /data/revisions/1.
- Add the INSERT statements to the table's schema file (/data/schema/[tablename].sql). I don't recommend this, because it's too easy to hit the "export to disk" button and overwrite the schema file without including the data.
I think hooks are the worst pattern that one could implement :)
Why not use the power of OOP? Such as the concept of driver classes, polymorphism, observer pattern or the bare essentials like simply extending the class?
PHP is not designed to be an event driven language...
An event emitter / listener pair is a direct, practical application of the Observable / Observer pattern. Perhaps I wasn't sufficiently clear on what I meant, but the Observable pattern is precisely what I was talking about.