-
-
Save ivanionut/c9f8e0dbd2e4e8737d4601364dff0973 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component accessors = true{ | |
property fw; | |
public function onLoad( beanfactory ){ | |
beanfactory | |
// Underscore.cfc - https://russplaysguitar.github.io/UnderscoreCF/ | |
.declare( "_" ).aliasFor( "underscoreUtil" ).done() | |
// qb - https://qb.ortusbooks.com/ | |
.declare("BaseGrammar").instanceOf("qb.models.Grammars.BaseGrammar").done() | |
.declare("MySQLGrammar").instanceOf("qb.models.Grammars.MySQLGrammar").done() | |
.declare("QueryUtils").instanceOf("qb.models.Query.QueryUtils").done() | |
.declare("QueryBuilder").instanceOf("qb.models.Query.QueryBuilder") | |
.withOverrides({ | |
grammar: beanfactory.getBean("MySQLGrammar"), | |
utils: beanfactory.getBean("QueryUtils"), | |
returnFormat: fw1Config.qb.returnFormat // sempre query | |
}).asTransient().done() | |
.declare("SchemaBuilder").instanceOf("qb.models.Schema.SchemaBuilder") | |
.asTransient() | |
.withOverrides({ | |
grammar: beanfactory.getBean("MySQLGrammar") | |
}).done() | |
// Aliases | |
.declare( "MySQLGrammar@qb" ).aliasFor( "MySQLGrammar" ).done() | |
.declare( "QueryBuilder@qb" ).aliasFor( "QueryBuilder" ).done() | |
.declare( "SchemaBuilder@qb" ).aliasFor( "SchemaBuilder" ).done() | |
.declare( "WireBox" ).asValue({ | |
getInstance: ( name, initArguments = {} ) => { | |
// Check if a CFC path was passed and instantiate it | |
if ( fileExists( expandPath( name.replace( ".", "/", "all" ) & ".cfc" ) ) ) { | |
return createObject( "component", name ); | |
} | |
// Otherwise it's a bean to fetch from a bean factory | |
else { | |
// Parse object@module to get subsystem | |
var module = name.listToArray( "@" ).last(); | |
return variables.fw.getBeanFactory( module ).getBean( name, initArguments ); | |
} | |
} | |
}).done() | |
.declare( "MigrationService" ).instanceOf("cfmigrations.models.MigrationService") | |
.withOverrides({ | |
wirebox : beanfactory.getBean( "WireBox" ), | |
migrationsDirectory : "/resources/database/migrations", | |
datasource : "my_datasource", | |
migrationsTable : "cfmigrations", | |
defaultGrammar:"MySQLGrammar@qb" | |
}).done() | |
; | |
beanFactory.load(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment