dbv icon indicating copy to clipboard operation
dbv copied to clipboard

Callback hooks

Open victorstanciu opened this issue 12 years ago • 4 comments

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.

victorstanciu avatar Nov 23 '12 16:11 victorstanciu

Would callback hooks be a way to provide initial data to schema objects, or would that be a separate issue?

davidcroda avatar Nov 24 '12 02:11 davidcroda

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:

  1. Create a revision script for each table with all the INSERT statements, and place them in /data/revisions/1.
  2. 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.

victorstanciu avatar Nov 24 '12 06:11 victorstanciu

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...

feketegy avatar Nov 27 '12 18:11 feketegy

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.

victorstanciu avatar Nov 27 '12 18:11 victorstanciu