Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[WIP]Sanitize in model #1374
Work in progress - Do not merge
This pr implements sanitization rules as requested in http://www.yiiframework.com/forum/index.php/topic/29362-cmodelsanitize/
Why this is needed/usefull?
Validators can be used to achive the same goal. But there is a difference in concept. Validators should just validate data not change(sanitize) it. If I validate user input I should just receive a feedback if it is valid or not. A validator should not affect data it validates.
Sanitization can be used to clean user data, make sure a number is non-negative or whatever is wanted. If we use a sanitizer we expect the data to be changed, regardless if it is valid(or sanitize it before validating).
Whats included, whats not
Implementation follows validators. There is some code duplication which can't be avoided without moving functionality from valdators to more abstract methods (or creating some useless aliases).
Some unit-tests are included, I will rework them, as soon as I know this is considered.
Documentation is todo. (See tests for examples)
Only 3 core-sanitizers are included. I will create some more as soon as I know if this is considered
For example you can do same things:
What you try to do with this PR? Change brilliant Yii approach? Thanks, i pass. Sure 90% of community pass too.
P.S. Try to perceive that Yii «validators» is «validators or/and sanitizators». For example file validator is validator + sanitizator.
I know the same can be achieved using validatory. But thats not the point.
This is about to have a 'clean' way to seperate data changing methods from pure readers. Also sanitizing data has not much todo with validating as it is contextfree and is used without relying on the current state of the model( real validators have to in the most cases)
I could also create a special scenario to seperate validators from, sanitizors but I doubt that this is the way to go.
Send via github for android. Sorry for not formatting the comment