danvega / hyrule Goto Github PK
View Code? Open in Web Editor NEWValidation framework for ColdFusion
Validation framework for ColdFusion
About Hyrule ------------------------------------------------------------------------------------- Hyrule is a validation framework for ColdFusion. Contrary to popular belief it's not just for ORM (Hibernate) based applications. The Hyrule framework will work with ColdFusion 9+ applications that use a model driven behavior for business objects. All this means is that use a class (component) to describe your objects such as user, person or employee. This framework gives you multiple ways to declare your validation rules or as the framework refers to them, constraints. Once you have defined your constraints you can pass in an object to the framework and it will let you know if it passes validation. This approach gives you a simple way to perform data validation in your object oriented based applications. This framework was created because there was a real need for it. When I started building most of my applications in a model driven form it became clear that there had to be an easier way of validating data. My inspiration was and still is the Hibernate Validator project from the Java community. This project also wouldn't be where it is today without the help of some amazing people. In no particular order they are: Aaron Greenlee Lance Staples Tony Nelson Luis Majano
Alright I've got another one...
If required is set to false but arguments.value
is not defined an exception is thrown, even if a default property value is provided.
Perhaps this function could be refactored a bit:
if (getRequired()) {
if (!structKeyExists(arguments, 'value') || !isSimpleValue(arguments.value))
return false;
if (len(trim(arguments.value)) == 0)
return false;
}
return true;
This would fix the exception however it seems like if you've defined a default value that should be passed along, so maybe the fix is further up the chain.
Thoughts?
I'll create a pull request if you agree with the changes.
Cheers.
If you have a property with a constraint of required="false"
it will fail validation as the processValidate
function returns false
by default. Line 53 of RequiredConstraint.cfc should be changed to return true;
I'm using the required constraint here for a property containing an object. Unfortunately this returns "false" regardless whether the property is set or not.
A closer look at the system.core.constraint.RequiredConstraint shows why:
public boolean function processValidate(any target, any property, any value){
....
if( isSimpleValue(arguments.value) ) {
....
}
return false;
}
I think this should be the following?
public boolean function processValidate(any target, any property, any value){
....
if( isSimpleValue(arguments.value) ) {
....
}
return true;
}
Or maybe do some further checking depending on the type (if an array return arrayLen(arguments.value), if an object return true, if a struct return structCount(arguments.value) etc.)
Hello,
I've been using the original version of Hyrule, and I love it, but I just recently started using the updated version of the framework. Everything is going great with it, except for this one issue:
I'm using the validator constraint on a property, and it does not appear to be accessing the property. When I call the hyrule.validate(ent) method, it does not display a message.
Here is my code for the Entity:
component persistent="true" table="tr_customers"
{
property name=customerID" ormtype="int" fieldtype="id" generator="identity" ;
/**
* @validator "testValid"
*/
property name="firstName" type="string" ;
public any function testValid() {
return false;
}
}
Here is the calling code:
cust = EntityNew("Customer");
hyrule = new hyrule.system.core.hyrule();
result = hyrule.validate(cust);
WriteDump(result);
The dump shows an empty array for errors, but it should show an error "The field firstName did not pass validation."
I'm not sure if it's something I'm missing in the code, or if this is a bug.
Please help.
Thank you.
}
Running on 2016 CF, line 48 inside ValidationMessageProvider.cfc I'm getting an exception for a missing comma-separator inside throw() method.
throw( type="ValidationMessage"
message="There is no message defined for type '#lcase(type)#'"
);
fix
throw( type="ValidationMessage",
message="There is no message defined for type '#lcase(type)#'"
);
you know the drill
The docs mention a "samples" folder, however, I don't see it in the repo. Did it get moved?
I'm looking at adding Hyrule to my project. However, I heard from someone that you were about to do a major rewrite.
https://github.com/blueriver/MuraCMS/issues/666
Should I wait until that happens or will the changes simply be under the hood?
Thanks,
Matt
When the isUnique constraint is used on a field, it will always fail when attempting to update a record. The constraint queries the whole table for a record with a matching value but does not exclude itself so it will always fail because it is pre-existing in the database.
I'm very excited in using the rewritten hyrule in my projects - many thanks from my end for your work!!
And I've got a first little feature request for you: Can you please add the ability to return the errors from a single property to the hyrule.core.result.ValidationResult object? I'm thinking about the following changes:
in the already existing addError function modify the following line
variables.propertyErrorCache[arguments.property.name] = true
to the following two
param name="variables.propertyErrorCache.#arguments.property.name#" default="#arrayNew(1)#";
arrayAppend(variables.propertyErrorCache[arguments.property.name],error);
And afterwards add an additonal method called "propertyGetErrors":
public array function propertyGetErrors(required string propertyName){
var errors = arrayNew(1);
if( propertyHasError(arguments.propertyName) ){
errors = variables.propertyErrorCache[arguments.propertyName];
}
return errors;
}
This little enhancement would make my life a lot easier using hyrule.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.