Crystal 0.4 released
I’m very proud to announce the 0.4 Milestone release of the database toolkit Crystal.
New features
Simplified validation class
Most PHP validation libraries out there require writing complex arrays with validation rules. With Crystal 0.4 I want to change this.
// Crystal 0.3 validation - simple validation with 4 rules - 255 characters
$multiple_rules = array
(
'title' => array('rules' =>
array
(
'alpha_numeric',
'min_length' => array('5', 'message' => 'Minimum lenght 5 symbols'),
'max_length' => array('10', 'message' => 'Maximum lenght 10 symbols'),
'required'
)
);
// The same thing in Crystal 0.4 - 176 characters
$multiple_rules = array
(
'title' => array
('
alpha_numeric
| min_length: (5), message: Minimum length 5 symbols
| max_length: (10), message: Maximum length 10 symbols
| required
');
New methods
regexp
In Crystal 0.4 you can write your own validation rules using PHP regular expressions. For example:
// Validate username, consist of alpha-numeric (a-z, A-Z, 0-9), underscores, and has minimum
// 5 character and maximum 20 character
$username= 'user_name12';
$rules = array(
'username' => array('regexp: (/^[a-z\d_]{5,20}$/i)')
);
unique
The most important validation rule finally made it in Crystal.
// Requirements
// This validation method requires Crystal database instance
// $db = Crystal::db();
// $validation = Crystal::validation($rules, $data, $db);
// Options
// table - specify the name of the table you want to look in
// field - specify the field name, if not specified Crystal will use the field name you are validating.
// In the following example that will be 'email'
$rules = array(
'email' => array('unique , table: users, field: email, message : This email is already taken')
);
Miscellaneous
Crystal works faster and better with PostgreSQL. Crystal doesn't throw deprecation warnings in PHP 5.3. If you need more details about the updates you can check the changelog.
What's next
Crystal 0.4 is a release focused on speed and syntax optimizations mostly in the validation class. The next milestone - 0.5 will be focused on the database manipulation module.