PHP

Using Mystique with PHP

Mystique requires php 5.4 or higher

Composer (recommended)

Add the following to your root composer.json:

require: [
"zoopcommerce/mystique":
    "~1.0"
]

This will automatically install and update minor versions whenever you use composer update. Composer will also set up autoloading.

Without Composer

Place the mystique source somewhere in your project. Set up autoloading for the ./php/lib/Zoop directory. Mystique is PSR0 compliant for easy autoloading.

Validators

To use a validator, first create an instance. Any options can be passed to the constructor in an associative array:

$validator = new Zoop/Mystique/Length(['min' => 4, 'max' => 50]);

Then call isValid to test a value

$result = $validator->isValid('123456');

The returned Result object contains the validation result:

if ( ! $result->getValue()){
    //validation failed
} else {
    //validation passed
}

The returned Result object may also contain an array of validation messages:

echo implode(' ', $result->getMessages()); //display any messages

Chains

Chains can be used to string validators together. Eg:

$validator = new Zoop/Mystique/Chain(['validators' => [
        new Zoop/Mystique/Alpha,
        new Zoop/Mystique/Length(['min' => 4, 'max' => 50])
    ]]);

English translations for validator messages are provided (if you would like to add more languages, that would be great!).