Load mach-ii include programatically

0 views
Skip to first unread message

shuns

unread,
Nov 16, 2008, 8:04:25 PM11/16/08
to Mach-II for CFML
Hi,

I was wondering if it is possible to load a mach-ii include file
programatically? I have had a look at the "loadIncludes" function in
the AppFactory.cfc and as expected all include related functionality
is private and setup to run only when the config file is first parsed.

The reason why I would like to be able to do this is becasue I have an
"environment" setting in a base config and I would like to be able to
change the between "environments" such as development, test,
production and have the appropriate config for each of those override
certain settings in the base config.

Is this possible in any way?

Peter J. Farrell

unread,
Nov 16, 2008, 8:40:25 PM11/16/08
to mach-ii-for...@googlegroups.com
shuns said the following on 11/16/2008 7:04 PM:

> Hi,
>
> I was wondering if it is possible to load a mach-ii include file
> programatically? I have had a look at the "loadIncludes" function in
> the AppFactory.cfc and as expected all include related functionality
> is private and setup to run only when the config file is first parsed.
>
We specifically did not open out programmatic loading of includes based
on programmatic conditions because it can become a severe mess as
applications grow in size (and I've never heard of an application ever
shrink in size before). I'm always weary adding anything to the xml
that is reminiscent of looking like if/elseif/else type of stuff as they
really does open up Pandora's box. See more discussion below...

> The reason why I would like to be able to do this is becasue I have an
> "environment" setting in a base config and I would like to be able to
> change the between "environments" such as development, test,
> production and have the appropriate config for each of those override
> certain settings in the base config.
>
> Is this possible in any way?
Usually, the best way is to create a Property.cfc to set environment
specific properties based on something like the server name (one of the
few places where I cheat say it is ok to access the cgi scope or you
could use Java classes to get at the machine name). Here is an example:
http://greatbiztoolsllc-trac.cvsdude.com/mach-ii/wiki/FAQLoadingApplicationVariables#a2.CreateappPropery.cfcinthepropertydirectory

You could easily modify the configure method to call a specific method
based on the server name.

This is an area we are going to examine and improve upon in Mach-II 1.8
-- with environment type properties. I've never come across a situation
where you want environment specific event-handlers or listeners -- it's
always properties being used to programmatically change the way other
elements in your application behave. We're not sure if we are going to
solve it by offering an environment or platform property.cfc that comes
bundled with Mach-II or actually add to to the core of the framework or
it might be a combination of both. I've been toying of the idea of
adding hooks into Mach-II that can set the deployment mode (development,
staging, production, etc.) and having a bundled property.cfc to help
set the correct properties etc. depending on the mode. This is
definitely an area that other frameworks (both CFML and non-CFML like
Spring / Struts / CakePHP) have struggled with finding an elegant
solution for both simple situations and the more complex deployment
enterprise level situations.

Lastly, you can use bindable property placeholders to drive the
configuration of listeners, filters and plugins:
http://greatbiztoolsllc-trac.cvsdude.com/mach-ii/wiki/BindablePropertyPlaceholders

Best,
.Peter

Net Grow - Shaun

unread,
Nov 16, 2008, 8:47:19 PM11/16/08
to mach-ii-for...@googlegroups.com
Thanks for the timely response peter, I will have a look into those options
and see how I go. I was actually thinking of Rails when choosing:
development, test & production :P

Regards,
shuns

Net Grow - Shaun

unread,
Nov 16, 2008, 9:38:21 PM11/16/08
to mach-ii-for...@googlegroups.com
Hi Peter,

I had a look at that and currently I already have an application property
that holds mach-ii config options which are then able to be passed out to
the application's model so as to not tie it to mach-ii for calls such as
getProperty()

If I was to set config options per environment within a property they would
then be coded within that property rather than fed from an xml config file.
I already considered my own xml config file for environment properties, but
don't want to do this because the mach-ii config functionallity already
suits my needs perfectly.

I wasn't refering to programaticlly within the xml file i.e if else - thats
obviously a bad idea as you stated, as you are then just replication native
CF functionality. I was refering to within mach-ii based objects such as the
property, you could do something like:

<cffunction name="configure" ...>
<cfswitch expression="#getParamater("environment")#">
<cfcase value="development">
<cfset getAppManager().getIncludeManager().loadInclude(path) />
</cfcase>
...
</cfswitch>
</cffunction>

Any suggestions?

TIA.

----- Original Message -----
From: "Peter J. Farrell" <pe...@mach-ii.com>
To: <mach-ii-for...@googlegroups.com>
Sent: Monday, November 17, 2008 12:40 PM
Subject: [Mach-II] Re: Load mach-ii include programatically


>

Peter J. Farrell

unread,
Nov 16, 2008, 10:02:33 PM11/16/08
to mach-ii-for...@googlegroups.com
Net Grow - Shaun said the following on 11/16/2008 8:38 PM:

> Hi Peter,
>
> I had a look at that and currently I already have an application property
> that holds mach-ii config options which are then able to be passed out to
> the application's model so as to not tie it to mach-ii for calls such as
> getProperty()
>
> If I was to set config options per environment within a property they would
> then be coded within that property rather than fed from an xml config file.
> I already considered my own xml config file for environment properties, but
> don't want to do this because the mach-ii config functionallity already
> suits my needs perfectly.
>
> I wasn't refering to programaticlly within the xml file i.e if else - thats
> obviously a bad idea as you stated, as you are then just replication native
> CF functionality. I was refering to within mach-ii based objects such as the
> property, you could do something like:
>
> <cffunction name="configure" ...>
> <cfswitch expression="#getParamater("environment")#">
> <cfcase value="development">
> <cfset getAppManager().getIncludeManager().loadInclude(path) />
> </cfcase>
> ...
> </cfswitch>
> </cffunction>
>
> Any suggestions?
>
> TIA.
>
Can't suggestion anything that ties in with XML files right now as that
functionality just doesn't exist in the core yet. I can assure you that
Kurt and I just discussed environment like settings on Saturday via IM
and that it's something we're planning on tackling in 1.8. However, as
you already may have noticed there are many ways to accomplish this task.

You could however passed parsed XML for properties to the loadXML() to
the PropertyManager. The 'configXML' attribute is expecting an
XmlParse()'ed variable.

This is what suggest, please file a detailed enhancement request by
filing new tickets at trac.mach-ii.com. Please file one each for
programmatic loading of includes and one regarding environment
configuration.

Best,
.Peter

Net Grow - Shaun

unread,
Nov 16, 2008, 10:13:07 PM11/16/08
to mach-ii-for...@googlegroups.com
Hi Peter,

Thanks for the response.

Where would I get the parsed xml from? Is that available as an argument
somewhere?

> You could however passed parsed XML for properties to the loadXML() to
> the PropertyManager. The 'configXML' attribute is expecting an
> XmlParse()'ed variable.

I would file a ticket there if I was requesting a new feature, however in
this case I was merely asking if there was a way to do something of that
sort right now. Programatic includes was just one thought of the top of my
head, not necessarily that I wanted it, more I was just thinking of one
possible way to solve that as a problem.

I dare say that you guys working on the core will be able to come up with
the most balanced solution when you get around to tackling it, I am just
looking for the best way to solve the problem as of right now :)

The suggestion regarding injecting parsed XML sounds pretty good, I'm just
not sure where abouts to get it from ^.^

> This is what suggest, please file a detailed enhancement request by
> filing new tickets at trac.mach-ii.com. Please file one each for
> programmatic loading of includes and one regarding environment
> configuration.

Regards
Shuns


----- Original Message -----
From: "Peter J. Farrell" <pe...@mach-ii.com>
To: <mach-ii-for...@googlegroups.com>
Sent: Monday, November 17, 2008 2:02 PM
Subject: [Mach-II] Re: Load mach-ii include programatically


>

Peter J. Farrell

unread,
Nov 17, 2008, 12:51:32 AM11/17/08
to mach-ii-for...@googlegroups.com
Net Grow - Shaun said the following on 11/16/2008 9:13 PM:
Hi Peter,

Thanks for the response.

Where would I get the parsed xml from? Is that available as an argument 
somewhere?

  
You'd have to load your xml file you want using cffile yourself and run XmlParse on it.

You could however passed parsed XML for properties to the loadXML() to
the PropertyManager.  The 'configXML' attribute is expecting an
XmlParse()'ed variable.
    
I would file a ticket there if I was requesting a new feature, however in 
this case I was merely asking if there was a way to do something of that 
sort right now. Programatic includes was just one thought of the top of my 
head, not necessarily that I wanted it, more I was just thinking of one 
possible way to solve that as a problem.
  
Nope, it's not possible to load an include at runtime programmatically at this time.

I dare say that you guys working on the core will be able to come up with 
the most balanced solution when you get around to tackling it, I am just 
looking for the best way to solve the problem as of right now :)

The suggestion regarding injecting parsed XML sounds pretty good, I'm just 
not sure where abouts to get it from ^.^
  
You'd have to write a property.cfc and read the file you want manually, XmlParse it and then call getAppManager().getPropertyManager().loadXml(variableWithParsedXml)

.pjf

Net Grow - Shaun

unread,
Nov 17, 2008, 4:18:15 PM11/17/08
to mach-ii-for...@googlegroups.com
Hi Peter,
 
Yep, sounds good ty. I'll give that a go.
 
shuns
----- Original Message -----
Sent: Monday, November 17, 2008 4:51 PM
Subject: [Mach-II] Re: Load mach-ii include programatically

Net Grow - Shaun

unread,
Nov 17, 2008, 5:48:01 PM11/17/08
to mach-ii-for...@googlegroups.com
Hi Peter,
 
Yep that worked out nicely. Ty for suggestions.
 
shuns
----- Original Message -----
Sent: Monday, November 17, 2008 4:51 PM
Subject: [Mach-II] Re: Load mach-ii include programatically

Reply all
Reply to author
Forward
0 new messages