I start today a series of post on the usage and documentation of my EventManager for coldfusion. You can find more docs and svn code here.

### Initialize The EventManager

EventManager is done to work standalone or to be easily integrated with Coldspring. Both examples will be provided.

### Standalone



<cfset application.em = craeteObject('component','EventManager.EventManager').init() />

Init( Events:Array , Listeners:Array , XmlPath:String , AutowireEvents:Boolean , Debug:Boolean , Scope:String )

The init method takes the following arguments.

  • Events:Array - default arrayNew(1) - Array of structs representing the events to register.
  • Listeners:Array - default arrayNew(1) - Array of structs representing the listeners to register.
  • XmlPath:String - default "" - Relative Path to an xml file containing events and listeners to be registered.
  • AutowireEvents:Boolean - default false - If true any event create for being dispatched is autowired using beanInjector.
  • Debug:Boolean - default false - If true force Em to save a trace of any operation executed.
  • Scope:String - default 'request' - Says to Em how to save the tracing info if debug mode is true. Request use the request scope and clean up the trace memory any time the request die. Instance persists the informations into the EventManager instance itself.


<cfset events = arrayNew(1) />

<cfset event = structNew() />


.....add more events....


<cfset listeners = arrayNew(1) />

<cfset listener = structNew() />



<cfset listener.priority = 10 />

<cfset listener.cache = true />
.....add more listeners....

<cfset eventManager = createObject('component','EventManager.EventManager')
.init(events,listeners) />

### Xml Syntax via xmlPath

You can setUp your events/listeners using xml notation. The xmlPath argument you can pass to init mode represent the relative path to the xml config file.

<cfset eventManager = createObject('component','EventManager.EventManager')
.init(xmlPath='/myapp/config/eventmanager.xml') />

In init method using the xmlPath attribute will not overwrite or stop the eventManager from loading arrays of events and listeners if provided.

<code class="coldfusion"><cfset eventManager = createObject('component','EventManager.EventManager')<br />.init(events,listeners,'/myapp/config/eventmanager.xml') />	<br /></code><br />

The previuos example will load all the events from array and xml and then will register listeners from array and from the xml too.

See xml for schema details. In teh resource folder are present both .dtd and .xsd to validate your xml.

### Coldspring Tip

If laoded via coldspring you can use the great syntax tool to create arrays and struct from xml that coldpring shipd for free





myEvent


EventManager.Event


....... more events here ...








myEvent


evapp.listeners.mylistener
or




methodToFire


.................... more listeners










andreacfm