@@ -62,7 +62,7 @@ component accessors="true" serialize="false" singleton {
62
62
/**
63
63
* A resource bundle plugin for i18n capabilities
64
64
*/
65
- property name = " resourceService" inject = " ResourceService@cbi18n" ;
65
+ property name = " resourceService" inject = " provider: ResourceService@cbi18n" ;
66
66
67
67
/**
68
68
* Shared constraints that can be loaded into the validation manager
@@ -74,9 +74,6 @@ component accessors="true" serialize="false" singleton {
74
74
*/
75
75
property name = " registeredValidators" type = " Struct" ;
76
76
77
- // Unique manager id
78
- this .id = createUUID ();
79
-
80
77
/**
81
78
* Constructor
82
79
*
@@ -85,10 +82,8 @@ component accessors="true" serialize="false" singleton {
85
82
ValidationManager function init ( struct sharedConstraints = {} ){
86
83
// store shared constraints if passed
87
84
variables .sharedConstraints = arguments .sharedConstraints ;
88
- // Validators Path
89
- variables .validatorsPath = getDirectoryFromPath ( getMetadata ( this ).path ) & " validators" ;
90
85
// Register validators
91
- variables .registeredValidators = discoverValidators ( variables . validatorsPath ) ;
86
+ variables .registeredValidators = " " ;
92
87
// Register aliases
93
88
variables .validatorAliases = {
94
89
" items" : " arrayItem" ,
@@ -98,7 +93,26 @@ component accessors="true" serialize="false" singleton {
98
93
return this ;
99
94
}
100
95
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 ){
102
116
return directoryList ( arguments .path , false , " name" , " *.cfc" )
103
117
// don't do the interfaces
104
118
.filter ( function ( item ){
@@ -316,14 +330,16 @@ component accessors="true" serialize="false" singleton {
316
330
* @throws ValidationManager.InvalidValidatorType
317
331
*/
318
332
any function getValidator ( required string validatorType , required any validationData ){
333
+ var coreValidators = getRegisteredValidators ();
334
+
319
335
// Are we an alias?
320
336
if ( structKeyExists ( variables .validatorAliases , arguments .validatorType ) ) {
321
337
arguments .validatorType = variables .validatorAliases [ arguments .validatorType ];
322
338
}
323
339
324
340
// 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 ] );
327
343
}
328
344
329
345
// Else switch checks
0 commit comments