Giter Club home page Giter Club logo

hyrule's Introduction

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

hyrule's People

Contributors

coryasilva avatar d1rtym0nk3y avatar danvega avatar joebrislin avatar lstaples avatar nerdstep avatar samfarmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hyrule's Issues

RequiredConstraint exception when no value is passed in

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.

required constraint returns false for objects

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.)

validator constraint not accessing component

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.
}

throwing exception when (,) is not specified inside throw() method

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)#'"
);

Missing samples folder

The docs mention a "samples" folder, however, I don't see it in the repo. Did it get moved?

isUnique always fail when updating an ORM object

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.

Add a propertyGetErrors to hyrule.core.result.ValidationResult

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.