Skip to content

Commit 315ff9b

Browse files
committed
* Major bump of all dependencies
* New `InstanceOf` validator thanks to @homestar9 : #65 * New virtual app testing and tuning
1 parent b7b5f16 commit 315ff9b

15 files changed

+70
-36
lines changed

ModuleConfig.cfc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ component {
3030
function configure(){
3131
// Mixin our own methods on handlers, interceptors and views via the ColdBox UDF Library File setting
3232
settings = {
33+
// The default Validation manager
3334
manager : this.COLDBOX_VALIDATION_MANAGER,
34-
// i18nResource = "",
35+
// Global constraints
3536
sharedConstraints : {}
3637
};
3738
}

box.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
"cfpm:install":"echo '\".engine/adobe2021/WEB-INF/cfusion/bin/cfpm.sh\" install ${1}' | run",
5151
"install:2021":"run-script cfpm:install zip",
5252
"install:dependencies":"install && cd test-harness && install"
53+
},
54+
"installPaths":{
55+
"cbi18n":"modules/cbi18n/"
5356
}
5457
}

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Added
1313

1414
* Major bump of all dependencies
15+
* New `InstanceOf` validator thanks to @homestar9 : https://github.com/coldbox-modules/cbvalidation/pull/65
16+
* New virtual app testing and tuning
1517

1618
### Fixed
1719

@@ -21,7 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2123

2224
* Dropped ACF2016
2325

24-
2526
----
2627

2728
## [3.4.0] => 2022-JUN-27

models/ValidationManager.cfc

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ component accessors="true" serialize="false" singleton {
6262
/**
6363
* A resource bundle plugin for i18n capabilities
6464
*/
65-
property name="resourceService" inject="ResourceService@cbi18n";
65+
property name="resourceService" inject="provider:ResourceService@cbi18n";
6666

6767
/**
6868
* Shared constraints that can be loaded into the validation manager
@@ -74,9 +74,6 @@ component accessors="true" serialize="false" singleton {
7474
*/
7575
property name="registeredValidators" type="Struct";
7676

77-
// Unique manager id
78-
this.id = createUUID();
79-
8077
/**
8178
* Constructor
8279
*
@@ -85,10 +82,8 @@ component accessors="true" serialize="false" singleton {
8582
ValidationManager function init( struct sharedConstraints = {} ){
8683
// store shared constraints if passed
8784
variables.sharedConstraints = arguments.sharedConstraints;
88-
// Validators Path
89-
variables.validatorsPath = getDirectoryFromPath( getMetadata( this ).path ) & "validators";
9085
// Register validators
91-
variables.registeredValidators = discoverValidators( variables.validatorsPath );
86+
variables.registeredValidators = "";
9287
// Register aliases
9388
variables.validatorAliases = {
9489
"items" : "arrayItem",
@@ -98,7 +93,26 @@ component accessors="true" serialize="false" singleton {
9893
return this;
9994
}
10095

101-
public struct function discoverValidators( required string path ){
96+
/**
97+
* Lazy loader getter to get all the registered validators in the system
98+
*
99+
* @return The discovered map of validators and aliases
100+
*/
101+
struct function getRegisteredValidators(){
102+
if( isSimpleValue( variables.registeredValidators ) ){
103+
variables.registeredValidators = discoverValidators( getDirectoryFromPath( getMetadata( this ).path ) & "validators" );
104+
}
105+
return variables.registeredValidators;
106+
}
107+
108+
/**
109+
* Discover all the core validators found in the system
110+
*
111+
* @path The path to discover
112+
*
113+
* @return The discovered map of validators and aliases
114+
*/
115+
struct private function discoverValidators( required string path ){
102116
return directoryList( arguments.path, false, "name", "*.cfc" )
103117
// don't do the interfaces
104118
.filter( function( item ){
@@ -316,14 +330,16 @@ component accessors="true" serialize="false" singleton {
316330
* @throws ValidationManager.InvalidValidatorType
317331
*/
318332
any function getValidator( required string validatorType, required any validationData ){
333+
var coreValidators = getRegisteredValidators();
334+
319335
// Are we an alias?
320336
if ( structKeyExists( variables.validatorAliases, arguments.validatorType ) ) {
321337
arguments.validatorType = variables.validatorAliases[ arguments.validatorType ];
322338
}
323339

324340
// Are we a core validator?
325-
if ( structKeyExists( variables.registeredValidators, arguments.validatorType ) ) {
326-
return wirebox.getInstance( variables.registeredValidators[ arguments.validatorType ] );
341+
if ( structKeyExists( coreValidators, arguments.validatorType ) ) {
342+
return wirebox.getInstance( coreValidators[ arguments.validatorType ] );
327343
}
328344

329345
// Else switch checks

models/validators/InstanceOfValidator.cfc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ component extends="BaseValidator" accessors="true" singleton {
1010
* Constructor
1111
*/
1212
InstanceOfValidator function init(){
13-
variables.name = "InstanceOf";
13+
variables.name = "InstanceOf";
1414
return this;
1515
}
1616

@@ -38,9 +38,9 @@ component extends="BaseValidator" accessors="true" singleton {
3838
}
3939

4040
// value is valid if it is an object and of the correct type
41-
var r = (
42-
isObject( arguments.targetValue ) &&
43-
isInstanceOf( arguments.targetValue, arguments.validationData )
41+
var r = (
42+
isObject( arguments.targetValue ) &&
43+
isInstanceOf( arguments.targetValue, arguments.validationData )
4444
);
4545

4646
if ( !r ) {

readme.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/coldbox-modules/cbvalidation.svg?branch=development)](https://travis-ci.org/coldbox-modules/cbvalidation)
1+
[![cbvalidation CI](https://github.com/coldbox-modules/cbvalidation/actions/workflows/ci.yml/badge.svg)](https://github.com/coldbox-modules/cbvalidation/actions/workflows/ci.yml)
22

33
# WELCOME TO THE COLDBOX VALIDATION MODULE
44

@@ -17,7 +17,7 @@ Apache License, Version 2.0.
1717
## SYSTEM REQUIREMENTS
1818

1919
- Lucee 5.x+
20-
- Adobe ColdFusion 2016+
20+
- Adobe ColdFusion 2018+
2121

2222
## Installation
2323

@@ -129,30 +129,30 @@ this.constraints = {
129129
propertyName = {
130130
// The field under validation must be yes, on, 1, or true. This is useful for validating "Terms of Service" acceptance.
131131
accepted : any value
132-
132+
133133
// The field under validation must be a date after the set targetDate
134134
after : targetDate
135-
135+
136136
// The field under validation must be a date after or equal the set targetDate
137137
afterOrEqual : targetDate
138138

139139
// The field must be alphanumeric ONLY
140140
alpha : any value
141-
141+
142142
// The field under validation is an array and all items must pass this validation as well
143143
arrayItem : {
144144
// All the constraints to validate the items with
145145
}
146-
146+
147147
// The field under validation must be a date before the set targetDate
148148
before : targetDate
149-
149+
150150
// The field under validation must be a date before or equal the set targetDate
151151
beforeOrEqual : targetDate
152-
152+
153153
// The field under validation must be a date that is equal the set targetDate
154154
dateEquals : targetDate
155-
155+
156156
// discrete math modifiers
157157
discrete : (gt,gte,lt,lte,eq,neq):value
158158

@@ -162,7 +162,7 @@ this.constraints = {
162162
// max value
163163
max : value
164164

165-
// Validation method to use in the target object must return boolean accept the incoming value and target object
165+
// Validation method to use in the target object must return boolean accept the incoming value and target object
166166
method : methodName
167167

168168
// min value
@@ -182,7 +182,7 @@ this.constraints = {
182182
anotherfield:value, anotherfield:value
183183
}
184184

185-
// The field under validation must be present and not empty unless the `anotherfield` field is equal to the passed
185+
// The field under validation must be present and not empty unless the `anotherfield` field is equal to the passed
186186
requiredUnless : {
187187
anotherfield:value, anotherfield:value
188188
}

[email protected]

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"rewrites":{
1212
"enable":"true"
1313
},
14-
"webroot":"test-harness",
15-
"aliases":{
14+
"webroot":"test-harness",
15+
"aliases":{
1616
"/moduleroot/cbvalidation":"./"
1717
}
1818
},
1919
"openBrowser":"false",
20-
"cfconfig": {
21-
"file" : ".cfconfig.json"
22-
}
20+
"cfconfig":{
21+
"file":".cfconfig.json"
22+
}
2323
}

test-harness/box.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
"dependencies":{
88
"coldbox":"^6.0.0",
99
"cbi18n":"^3.0.0",
10-
"testbox":"*"
10+
"testbox":"*",
11+
"cbdebugger":"^3.5.0+64"
1112
},
1213
"installPaths":{
1314
"coldbox":"coldbox/",
1415
"testbox":"testbox/",
15-
"cbi18n":"modules/cbi18n/"
16+
"cbi18n":"modules/cbi18n/",
17+
"cbdebugger":"modules/cbdebugger/"
1618
}
1719
}

test-harness/config/Coldbox.cfc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
};
6666

6767
moduleSettings = {
68+
cbdebugger : {
69+
modules : { enabled : true, expanded : false },
70+
},
6871
cbvalidation : {
6972
sharedConstraints : {
7073
"sharedUser" : {

test-harness/layouts/Main.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
<div>
44
#renderView()#
55
</div>
6-
</cfoutput>
6+
</cfoutput>

0 commit comments

Comments
 (0)