Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions wheels/Plugins.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
<cfset variables.$class.mixableComponents = "application,dispatch,controller,model,cache,base,connection,microsoftsqlserver,mysql,oracle,postgresql,h2">
<cfset variables.$class.incompatiblePlugins = "">
<cfset variables.$class.dependantPlugins = "">
<cfset variables.$class.events = {
OnApplicationStart = ArrayNew(1),
OnApplicationEnd = ArrayNew(1),
OnRequestStart = ArrayNew(1),
OnRequestEnd = ArrayNew(1),
OnSessionStart = ArrayNew(1),
OnSessionEnd = ArrayNew(1),
OnError = ArrayNew(1),
OnMissingTemplate = ArrayNew(1)
}>


<cffunction name="init">
Expand Down Expand Up @@ -33,7 +43,7 @@
<!--- incompatibility --->
<cfset $determineIncompatible()>
<!--- dependancies --->
<cfset $determinDependancy()>
<cfset $determineDependancy()>

<cfreturn this>
</cffunction>
Expand Down Expand Up @@ -129,6 +139,11 @@
<cfset variables.$class.incompatiblePlugins = ListAppend(variables.$class.incompatiblePlugins, loc.iPlugins)>
</cfif>
</cfif>
<cfif StructKeyExists(loc.plugin, "events")>
<cfloop list="#loc.plugin.events#" index="event">
<cfset $registerPluginEvent(loc.iPlugins, event)>
</cfloop>
</cfif>
</cfloop>
</cffunction>

Expand All @@ -154,7 +169,7 @@
</cffunction>


<cffunction name="$determinDependancy">
<cffunction name="$determineDependancy">
<cfset var loc = {}>

<cfloop collection="#variables.$class.plugins#" item="loc.iPlugins">
Expand Down Expand Up @@ -240,6 +255,10 @@
<cfreturn variables.$class.mixableComponents>
</cffunction>

<cffunction name="getEvents">
<cfreturn variables.$class.events>
</cffunction>

<cffunction name="inspect">
<cfreturn variables>
</cffunction>
Expand Down Expand Up @@ -278,5 +297,15 @@

<cfreturn q>
</cffunction>

<cffunction name="$registerPluginEvent" returntype="void">
<cfargument name="plugin" type="string" required="true">
<cfargument name="event" type="string" required="true">
<cfscript>
var loc = {};
loc.path = [variables.$class.pluginPath, arguments.plugin, "events", arguments.event & ".cfm"];
ArrayAppend(variables.$class.events[event], ArrayToList(loc.path, "/"));
</cfscript>
</cffunction>

</cfcomponent>
1 change: 1 addition & 0 deletions wheels/events/onapplicationend.cfm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<cffunction name="onApplicationEnd" returntype="void" access="public" output="false">
<cfargument name="applicationscope" type="struct" required="true">
<cfscript>
$loadPluginEvents('onapplicationend');
$include(template="#arguments.applicationscope.wheels.eventPath#/onapplicationend.cfm");
</cfscript>
</cffunction>
3 changes: 3 additions & 0 deletions wheels/events/onapplicationstart.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
for (loc.item in application.wheels.cacheSettings)
application.wheels.caches[loc.item] = $createObjectFromRoot(path="wheels", fileName="Cache", method="init", argumentCollection=application.wheels.cacheSettings[loc.item]);

// run any plugin events
$loadPluginEvents('onapplicationstart');

// run the developer's on application start code
$include(template="#application.wheels.eventPath#/onapplicationstart.cfm");
</cfscript>
Expand Down
3 changes: 3 additions & 0 deletions wheels/events/onapplicationstart/settings.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,7 @@
,xls="application/excel"
,xlsx="application/excel"
};

// plugin events
application.wheels.pluginEvents = {};
</cfscript>
5 changes: 4 additions & 1 deletion wheels/events/onerror.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
<cfargument name="eventName" type="any" required="true">
<cfscript>
var loc = {};

if (StructKeyExists(application, "wheels") && StructKeyExists(application.wheels, "initialized"))
{

$loadPluginEvents('onerror');

if (application.wheels.sendEmailOnError && Len(application.wheels.errorEmailAddress))
{
loc.mailArgs = {};
Expand Down
1 change: 1 addition & 0 deletions wheels/events/onmissingtemplate.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<cffunction name="$runOnMissingTemplate" returntype="void" access="public" output="true">
<cfargument name="targetpage" type="any" required="true">
<cfscript>
$loadPluginEvents('onmissingtemplate');
$header(statusCode=404, statustext="Not Found");
$includeAndOutput(template="#application.wheels.eventPath#/onmissingtemplate.cfm");
$abort();
Expand Down
1 change: 1 addition & 0 deletions wheels/events/onrequestend.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<cfscript>
if (application.wheels.showDebugInformation)
$debugPoint("requestEnd");
$loadPluginEvents('onrequestend');
$include(template="#application.wheels.eventPath#/onrequestend.cfm");
if (application.wheels.showDebugInformation)
$debugPoint("requestEnd,total");
Expand Down
1 change: 1 addition & 0 deletions wheels/events/onrequeststart.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
$simpleLock(name="controllerLock", execute="$clearControllerInitializationCache", type="exclusive");
if (!application.wheels.cacheRoutes)
$loadRoutes();
$loadPluginEvents('onrequeststart');
$include(template="#application.wheels.eventPath#/onrequeststart.cfm");
if (application.wheels.showDebugInformation)
$debugPoint("requestStart");
Expand Down
1 change: 1 addition & 0 deletions wheels/events/onsessionend.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<cfargument name="sessionscope" type="any" required="true">
<cfargument name="applicationscope" type="any" required="true">
<cfscript>
$loadPluginEvents('onsessionend');
$include(template="#application.wheels.eventPath#/onsessionend.cfm");
</cfscript>
</cffunction>
1 change: 1 addition & 0 deletions wheels/events/onsessionstart.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<cffunction name="$runOnSessionStart" returntype="void" access="public" output="false">
<cfscript>
$initializeRequestScope();
$loadPluginEvents('onsessionstart');
$include(template="#application.wheels.eventPath#/onsessionstart.cfm");
</cfscript>
</cffunction>
15 changes: 15 additions & 0 deletions wheels/global/internal.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -931,5 +931,20 @@ Should now call bar() instead and marking foo() as deprecated
application.wheels.incompatiblePlugins = application.wheels.PluginObj.getIncompatiblePlugins();
application.wheels.dependantPlugins = application.wheels.PluginObj.getDependantPlugins();
application.wheels.mixins = application.wheels.PluginObj.getMixins();
application.wheels.pluginEvents = application.wheels.PluginObj.getEvents();
</cfscript>
</cffunction>

<cffunction name="$loadPluginEvents" returntype="void" access="public" output="false">
<cfargument name="event" type="string" required="true">
<cfscript>
var loc = {};

if ( StructKeyExists(application.wheels.pluginEvents, arguments.event) AND ArrayLen(application.wheels.pluginEvents[arguments.event]) ) {
loc.events = application.wheels.pluginEvents[arguments.event];
for( loc.iEvent = 1; loc.iEvent <= ArrayLen(loc.events); loc.iEvent++ ) {
$include(template=loc.events[loc.iEvent]);
}
}
</cfscript>
</cffunction>