Skip to content

Commit

Permalink
Upgrade to version 3.0.1 of FW/1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Bingham committed Apr 23, 2015
1 parent 02a3b72 commit e92fd0c
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ component extends = "framework.one" {
, resetPasswordEmailSubject = ""
, whitelist = "^admin#variables.framework.subsystemDelimiter#security,^public#variables.framework.subsystemDelimiter#" // list of unsecure actions - by default all requests require authentication
}
, version = "2015.3.20"
, version = "2015.4.23"
};
// override config in development mode
if (local.config.development) {
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 2015.4.23

- Upgrade to version 3.0.1 of FW/1.

Version 2015.3.20

- General refactoring.
Expand Down
110 changes: 55 additions & 55 deletions framework/ioc.cfc
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
component {
variables._fw1_version = "3.0";
variables._di1_version = "1.0";
variables._fw1_version = "3.0.1";
variables._di1_version = "1.0.0";
/*
Copyright (c) 2010-2015, Sean Corfield
Expand All @@ -18,7 +18,7 @@ component {
*/

// CONSTRUCTOR

public any function init( string folders, struct config = { } ) {
variables.folders = folders;
variables.config = config;
Expand All @@ -41,7 +41,7 @@ component {
}
return this;
}

// PUBLIC METHODS

// programmatically register an alias
Expand All @@ -51,7 +51,7 @@ component {
return this;
}


// programmatically register new beans with the factory (add a singleton name/value pair)
public any function addBean( string beanName, any beanValue ) {
discoverBeans( variables.folders );
Expand All @@ -60,16 +60,16 @@ component {
};
return this;
}


// return true if the factory (or a parent factory) knows about the requested bean
public boolean function containsBean( string beanName ) {
discoverBeans( variables.folders );
return structKeyExists( variables.beanInfo, beanName ) ||
( structKeyExists( variables, 'parent' ) && variables.parent.containsBean( beanName ) );
}


// programmatically register new beans with the factory (add an actual CFC)
public any function declareBean( string beanName, string dottedPath, boolean isSingleton = true, struct overrides = { } ) {
discoverBeans( variables.folders );
Expand All @@ -80,8 +80,8 @@ component {
singleDir = singular( listLast( dottedPart, '.' ) );
}
var cfcPath = replace( expandPath( '/' & replace( dottedPath, '.', '/', 'all' ) & '.cfc' ), chr(92), '/', 'all' );
var metadata = {
name = beanName, qualifier = singleDir, isSingleton = isSingleton,
var metadata = {
name = beanName, qualifier = singleDir, isSingleton = isSingleton,
path = cfcPath, cfc = dottedPath, metadata = cleanMetadata( dottedPath ),
overrides = overrides
};
Expand All @@ -99,8 +99,8 @@ component {
variables.beanInfo[ beanName ] = metadata;
return this;
}


// return the requested bean, fully populated
public any function getBean( string beanName ) {
discoverBeans( variables.folders );
Expand All @@ -112,7 +112,7 @@ component {
throw 'bean not found: #beanName#';
}
}

// convenience API for metaprogramming perhaps?
public any function getBeanInfo( string beanName = '', boolean flatten = false,
string regex = '' ) {
Expand Down Expand Up @@ -157,8 +157,8 @@ component {
public string function getVersion() {
return variables.config.version;
}


// return true iff bean is known to be a singleton
public boolean function isSingleton( string beanName ) {
discoverBeans( variables.folders );
Expand All @@ -174,8 +174,8 @@ component {
return false; // we don't know the bean therefore it is not a managed singleton
}
}


// given a bean (by name, by type or by value), call the named
// setters with the specified property values
public any function injectProperties( any bean, struct properties ) {
Expand All @@ -192,8 +192,8 @@ component {
}
return bean;
}


// empty the cache and reload all the singleton beans
// note: this does not reload the parent - if you have parent/child factories you
// are responsible for dealing with that logic (it's safe to reload a child but
Expand All @@ -218,16 +218,16 @@ component {
variables.listeners = head;
return this;
}


// set the parent bean factory
public any function setParent( any parent ) {
variables.parent = parent;
return this;
}

// PRIVATE METHODS

private boolean function beanIsTransient( string singleDir, string dir, string beanName ) {
return singleDir == 'bean' ||
structKeyExists( variables.transients, dir ) ||
Expand Down Expand Up @@ -257,7 +257,7 @@ component {
}
}


private struct function cleanMetadata( string cfc ) {
var baseMetadata = metadata( cfc );
var iocMeta = { setters = { }, pruned = false };
Expand Down Expand Up @@ -323,14 +323,14 @@ component {
private any function construct( string dottedPath ) {
return createObject( 'component', dottedPath );
}


// in case an extension point wants to override actual metadata retrieval:
private any function metadata( string dottedPath ) {
return getComponentMetadata( dottedPath );
}


private string function deduceDottedPath( string baseMapping, string basePath ) {
var cfcPath = left( baseMapping, 1 ) == '/' ?
( len( baseMapping ) > 1 ? right( baseMapping, len( baseMapping ) - 1 ) : '' ) :
Expand Down Expand Up @@ -374,8 +374,8 @@ component {
}
onLoadEvent();
}


private void function discoverBeansInFolder( string mapping ) {
var folder = replace( expandPath( mapping ), chr(92), '/', 'all' );
var dotted = deduceDottedPath( mapping, folder );
Expand All @@ -402,8 +402,8 @@ component {
var singleDir = singular( dir );
var beanName = listLast( relPath, '/' );
var dottedPath = dotted & replace( relPath, '/', '.', 'all' );
var metadata = {
name = beanName, qualifier = singleDir, isSingleton = !beanIsTransient( singleDir, dir, beanName ),
var metadata = {
name = beanName, qualifier = singleDir, isSingleton = !beanIsTransient( singleDir, dir, beanName ),
path = cfcPath, cfc = dottedPath, metadata = cleanMetadata( dottedPath )
};
if ( structKeyExists( variables.beanInfo, beanName ) ) {
Expand All @@ -420,8 +420,8 @@ component {
}
}
}


private struct function findSetters( any cfc, struct iocMeta ) {
var liveMeta = { setters = iocMeta.setters };
if ( !iocMeta.pruned ) {
Expand Down Expand Up @@ -450,8 +450,8 @@ component {
}
return liveMeta;
}


private any function forceCache( any bean, string beanName) {
var info = variables.beanInfo[ beanName ];
if ( info.isSingleton ) {
Expand All @@ -469,7 +469,7 @@ component {
return structKeyExists( variables.beanInfo[ beanName ], 'value');
}


private void function logMissingBean( string beanName, string resolvingBeanName = '' ) {
var sys = createObject( 'java', 'java.lang.System' );
if ( len( resolvingBeanName ) ) {
Expand All @@ -478,8 +478,8 @@ component {
sys.out.println( 'bean not found: #beanName#' );
}
}


private void function missingBean( string beanName, string resolvingBeanName = '' ) {
if ( variables.config.strict ) {
if ( len( resolvingBeanName ) ) {
Expand Down Expand Up @@ -541,8 +541,8 @@ component {
// unknown
return { };
}


private any function resolveBean( string beanName ) {
// do enough resolution to create and initialization this bean
// returns a struct of the bean and a struct of beans and setters still to run
Expand Down Expand Up @@ -619,8 +619,8 @@ component {
}
}
}


private struct function resolveBeanCreate( string beanName, struct accumulator ) {
var bean = 0;
if ( structKeyExists( variables.beanInfo, beanName ) ) {
Expand Down Expand Up @@ -686,7 +686,7 @@ component {
bean = bean,
overrides = overrides
};
accumulator.injection[ beanName ] = setterMeta;
accumulator.injection[ beanName ] = setterMeta;
for ( var property in setterMeta.setters ) {
accumulator.dependencies[ beanName ][ property ] = true;
if ( structKeyExists( overrides, property ) ) {
Expand Down Expand Up @@ -726,27 +726,27 @@ component {
}
return accumulator;
}


private void function setupFrameworkDefaults() {
param name = "variables.config.recurse" default = true;
param name = "variables.config.strict" default = false;

if ( !structKeyExists( variables.config, 'exclude' ) ) {
variables.config.exclude = [ ];
}
for ( var elem in variables.autoExclude ) {
arrayAppend( variables.config.exclude, replace( elem, chr(92), '/', 'all' ) );
}

// install bean factory constant:
variables.beanInfo.beanFactory = { value = this, isSingleton = true };
if ( structKeyExists( variables.config, 'constants' ) ) {
for ( var beanName in variables.config.constants ) {
variables.beanInfo[ beanName ] = { value = variables.config.constants[ beanName ], isSingleton = true };
}
}

variables.transients = { };
if ( structKeyExists( variables.config, 'transients' ) ) {
for ( var transientFolder in variables.config.transients ) {
Expand All @@ -765,7 +765,7 @@ component {
if ( !structKeyExists( variables.config, 'omitDirectoryAliases' ) ) {
variables.config.omitDirectoryAliases = false;
}

variables.config.version = variables._di1_version;
}

Expand All @@ -774,10 +774,10 @@ component {
// constructed and injected, but before init-method is called on anything
private void function setupInitMethod( string name, any bean ) {
}


private string function singular( string plural ) {
if ( structKeyExists( variables.config, 'singulars' ) &&
if ( structKeyExists( variables.config, 'singulars' ) &&
structKeyExists( variables.config.singulars, plural ) ) {
return variables.config.singulars[ plural ];
}
Expand All @@ -789,5 +789,5 @@ component {
}
return single;
}

}
Loading

0 comments on commit e92fd0c

Please sign in to comment.