Basic Support for Plugin Events #18

Closed
wants to merge 3 commits into
from

Conversation

6 participants
@awmichel

awmichel commented Sep 1, 2011

This allows for plugins to add additional code to the Application events, it's very basic and only allows one injection point (just before the developer's events are included) but solves an issue I was having while developing an plugin.

Plugin Event Process

  1. Events are registered with Wheels through the plugin's init function by defining the events to be included in a events variable. For each event in this list, Wheels will include a file with the same name inside an events folder in the plugin's folder.
  2. These events are processed inside the $pluginsProcess function, which works by adding them to a struct of arrays where each event is a struct key containing an array of paths to the specific event in the plugin's event folder.
  3. Finally each event in the wheels/events directory calls a $loadPluginEvents method with the event name which loops through the array inside the event struct and includes the event code from the plugin. This happens just before the developer's events in most cases, onError and onMissingTemplate occur at slightly different points.

Example

<cfset this.events = "onapplicationstart,onrequeststart,onsessionstart">
Will include the following files

  • /plugins/SamplePlugin/events/onapplicationstart.cfm
  • /plugins/SamplePlugin/events/onrequeststart.cfm
  • /plugins/SamplePlugin/events/onsessionstart.cfm

This probably isn't the most robust or feature rich way of accomplishing the task, but it does provide a crude method for plugin developers to include custom code without forcing the developer to add the code to their event files. Also since it's included before the plugin developer's code, they can still override plugin settings in their own event.

@rip747

This comment has been minimized.

Show comment Hide comment
@rip747

rip747 Sep 11, 2011

i'm thinking that a better way to accomplish this would be to copy callbacks and allow plugins to register methods to be executed in each position in the application lifecycle. thoughts?

rip747 commented Sep 11, 2011

i'm thinking that a better way to accomplish this would be to copy callbacks and allow plugins to register methods to be executed in each position in the application lifecycle. thoughts?

@awmichel

This comment has been minimized.

Show comment Hide comment
@awmichel

awmichel Sep 11, 2011

There are a number way this could be improved, ideally I would like to have it invoke a function stored in a standardized file for events. Each plugin could have an eventHandlers.cfc file in it's root where it would use functions named as the event they execute with.

I'd also like to expand the scope of the events to not only include Application events, but also allow other plugins to define events and additionally events inside the Wheels execution itself. Say if you want to add some extra logic the delete method for model objects, announceEvent('beforeDeleteModelObject') and any plugin could then add extra code to be executed at that point. I believe the Log User Actions plugin achieves this currently by overriding a $addToDeleteClause method, simply adding a function to an events file sounds much cleaner right?

I haven't dug into the code, but does plugin dependency checking modify the order that the plugins are loaded? If it doesn't that may need to be addressed before plugins will truly be able to define events and other plugins register those events.

The event system I describe above is heavily inspired by the event system from MuraCMS, check out the code to see what I'm describing in action.

If this all sounds good, I'll start working on the changes to my initial commits.

There are a number way this could be improved, ideally I would like to have it invoke a function stored in a standardized file for events. Each plugin could have an eventHandlers.cfc file in it's root where it would use functions named as the event they execute with.

I'd also like to expand the scope of the events to not only include Application events, but also allow other plugins to define events and additionally events inside the Wheels execution itself. Say if you want to add some extra logic the delete method for model objects, announceEvent('beforeDeleteModelObject') and any plugin could then add extra code to be executed at that point. I believe the Log User Actions plugin achieves this currently by overriding a $addToDeleteClause method, simply adding a function to an events file sounds much cleaner right?

I haven't dug into the code, but does plugin dependency checking modify the order that the plugins are loaded? If it doesn't that may need to be addressed before plugins will truly be able to define events and other plugins register those events.

The event system I describe above is heavily inspired by the event system from MuraCMS, check out the code to see what I'm describing in action.

If this all sounds good, I'll start working on the changes to my initial commits.

@awmichel awmichel closed this Sep 11, 2011

@awmichel awmichel reopened this Sep 11, 2011

@devalnor

This comment has been minimized.

Show comment Hide comment
@devalnor

devalnor Jul 23, 2012

I vote for this feature ^^

I vote for this feature ^^

@snaquaye

This comment has been minimized.

Show comment Hide comment
@snaquaye

snaquaye Sep 3, 2012

I vote for this feature

snaquaye commented Sep 3, 2012

I vote for this feature

@andybellenie

This comment has been minimized.

Show comment Hide comment
@andybellenie

andybellenie Sep 19, 2012

Contributor

Can't you just run the plugin code using a filter instead?

Contributor

andybellenie commented Sep 19, 2012

Can't you just run the plugin code using a filter instead?

@rip747

This comment has been minimized.

Show comment Hide comment
@rip747

rip747 Sep 19, 2012

while that's true for plugins that would live in the onrequeststart event. i think though what devs want is to be able to have plugin get configured when wheels first loads. I think we've all run into this problem where we have to have a settings methods in our plugins that we call in each of the plugin methods to make any configuration is done.

rip747 commented Sep 19, 2012

while that's true for plugins that would live in the onrequeststart event. i think though what devs want is to be able to have plugin get configured when wheels first loads. I think we've all run into this problem where we have to have a settings methods in our plugins that we call in each of the plugin methods to make any configuration is done.

@perdjurner

This comment has been minimized.

Show comment Hide comment
@perdjurner

perdjurner Jul 14, 2014

Owner

This sounds like a good change to me.

If possible, can you resubmit this pull request on the "master" branch instead?

Owner

perdjurner commented Jul 14, 2014

This sounds like a good change to me.

If possible, can you resubmit this pull request on the "master" branch instead?

@perdjurner perdjurner closed this Jul 14, 2014

scahyono added a commit that referenced this pull request Jul 14, 2014

Merge pull request #18 from cfwheels/master
skip ACF/MSSQL test during Pull Request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment