Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed May 15, 2021
2 parents 8a38c19 + ea42a3e commit fcccd25
Show file tree
Hide file tree
Showing 60 changed files with 3,039 additions and 1,194 deletions.
105 changes: 22 additions & 83 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
/**
*********************************************************************************
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.coldbox.org | www.luismajano.com | www.ortussolutions.com
********************************************************************************
* Copyright since 2020 by Ortus Solutions, Corp
* www.ortussolutions.com
* ---
*/
component {

// Module Properties
this.title = "validation";
this.author = "Luis Majano";
this.webURL = "http://www.ortussolutions.com";
this.description = "This module provides server-side validation to ColdBox applications";
this.version = "@build.version@[email protected]@";
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
this.viewParentLookup = true;
// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
this.layoutParentLookup = true;
this.title = "validation";
this.author = "Luis Majano";
this.webURL = "https://www.ortussolutions.com";
this.description = "This module provides server-side validation to ColdBox applications";
this.version = "@build.version@[email protected]@";

// Model Namespace
this.modelNamespace = "cbvalidation";
this.modelNamespace = "cbvalidation";
// CF Mapping
this.cfmapping = "cbvalidation";
// Auto-map models
this.autoMapModels = true;
this.cfmapping = "cbvalidation";
// Helpers
this.applicationHelper = [ "helpers/Mixins.cfm" ];

// Module Dependencies That Must Be Loaded First, use internal names or aliases
this.dependencies = [ "cbi18n" ];
// ColdBox Static path to validation manager
Expand All @@ -32,95 +29,37 @@ component {
*/
function configure(){
// Mixin our own methods on handlers, interceptors and views via the ColdBox UDF Library File setting
arrayAppend(
controller.getSetting( "ApplicationHelper" ),
"#moduleMapping#/models/Mixins.cfm"
);
settings = {
manager : this.COLDBOX_VALIDATION_MANAGER,
// i18nResource = "",
sharedConstraints : {}
};
}

/**
* Fired when the module is registered and activated.
*/
function onLoad(){
var configSettings = controller.getConfigSettings();
// parse parent settings
parseParentSettings();
// Did you change the validation manager?
if ( configSettings.validation.manager != this.COLDBOX_VALIDATION_MANAGER ) {
if ( variables.settings.manager != this.COLDBOX_VALIDATION_MANAGER ) {
binder
.map(
alias = "validationManager@cbvalidation",
force = true
)
.to( configSettings.validation.manager )
.to( variables.settings.manager )
.asSingleton();
}
// setup shared constraints
wirebox
.getInstance( "validationManager@cbvalidation" )
.setSharedConstraints( configSettings.validation.sharedConstraints );
.setSharedConstraints( variables.settings.sharedConstraints );
}

/**
* Fired when the module is unregistered and unloaded
*/
function onUnload(){
var appHelperArray = controller.getSetting( "ApplicationHelper" );
var mixinToRemove = "#moduleMapping#/models/Mixins.cfm";
var mixinIndex = arrayFindNoCase( appHelperArray, mixinToRemove );

// If the mixin is in the array
if ( mixinIndex ) {
// Remove it
arrayDeleteAt( appHelperArray, mixinIndex );
// Arrays passed by value in Adobe CF
controller.setSetting( "ApplicationHelper", appHelperArray );
}
}

/**
* Prepare settings and returns true if using i18n else false.
*/
private function parseParentSettings(){
/**
Sample :
validation = {
manager = "class path" // if overriding
sharedConstraints = {
name = {
field = { constraints here }
}
}
}
*/
// Read parent application config
var oConfig = controller.getSetting( "ColdBoxConfig" );
var validationDSL = oConfig.getPropertyMixin(
"validation",
"variables",
structNew()
);
var configStruct = controller.getConfigSettings();

// Default Config Structure
configStruct.validation = {
manager : this.COLDBOX_VALIDATION_MANAGER,
sharedConstraints : {}
};

// manager
if ( structKeyExists( validationDSL, "manager" ) ) {
configStruct.validation.manager = validationDSL.manager;
}
// shared constraints
if ( structKeyExists( validationDSL, "sharedConstraints" ) ) {
structAppend(
configStruct.validation.sharedConstraints,
validationDSL.sharedConstraints,
true
);
}
}

}
11 changes: 7 additions & 4 deletions box.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name":"ColdBox Validation",
"author":"Ortus Solutions <[email protected]>",
"version":"3.0.0",
"version":"3.1.0",
"location":"https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/cbvalidation/@build.version@/[email protected]@.zip",
"slug":"cbvalidation",
"type":"modules",
Expand Down Expand Up @@ -32,8 +32,11 @@
],
"scripts":{
"release":"recipe build/release.boxr",
"format":"cfformat run models/,test-harness/tests/,*.cfc --overwrite",
"format:watch":"cfformat watch models/,test-harness/tests/,*.cfc ./.cfformat.json",
"format:check":"cfformat check models/,test-harness/tests/,*.cfc"
"format":"cfformat run interfaces,models/,test-harness/tests/,ModuleConfig.cfc --overwrite",
"format:watch":"cfformat watch interfaces,models/,test-harness/tests/,ModuleConfig.cfc ./.cfformat.json",
"format:check":"cfformat check interfaces,models/,test-harness/tests/,ModuleConfig.cfc"
},
"installPaths":{
"cbi18n":"modules/cbi18n/"
}
}
Loading

0 comments on commit fcccd25

Please sign in to comment.