Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Callback hooks #5

victorstanciu opened this Issue Nov 23, 2012 · 4 comments


None yet
3 participants

victorstanciu commented Nov 23, 2012

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.

@ghost ghost assigned victorstanciu Nov 23, 2012


davidcroda commented Nov 24, 2012

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


victorstanciu commented Nov 24, 2012

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.

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


victorstanciu commented Nov 27, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment