opensourcepos / opensourcepos

Open Source Point of Sale is a web based point of sale application written in PHP using CodeIgniter framework. It uses MySQL as the data back end and has a Bootstrap 3 based user interface.
http://www.opensourcepos.org
Other
3.48k stars 2.19k forks source link

CI Events for Third-Party integrations #2608

Closed objecttothis closed 3 years ago

objecttothis commented 5 years ago

Background information

Please make sure you tick (add an x between the square brackets with no spaces) the following check boxes:

Installation information

New Feature

As discussed in #2315 and #1680 there is a need for us to have an Event Dispatcher to separate but facilitate Third-Party Integrations. I would like to use the CI library found at https://github.com/nathanmac/CodeIgniter-Events to do this. This is a light weight event listener/trigger library for CI to allow us to trigger events on CRUD operations. The listener third-party integrations can then take the data presented to it by the trigger (contents of the CRUD operation) and do its thing (send it to an API, process it, etc).

I'm guessing that in order for multiple third-party integrations to use the same data we will need to write a general listener/trigger pair for each CRUD operation type and then the Third-Party integrations call their own methods from within the listener. Otherwise if we left it up the the third party integrations to write their own listeners we could end up with a cluttered codespace with listeners.

For example, an Update Trigger would be placed into the Sales Controller or Model (The same trigger would get placed into Items since updates can be done there as well)

Events::trigger('item_update', $data_we_want_to_give_to_apis, 'array')

Then in an events library we put something like:

class Events { public function __construct() { Events::register('item_update', array($this, 'update_integrations')); }

public function update_integrations() { //call to this integration function with update data //call to another integration function with update data ... return $error_results; } }

Thoughts?

objecttothis commented 3 years ago

This will be resolved by the migration to CI 4 since it has built-in event sourcing.