1. Go to this page and download the library: Download marco-fiset/flute library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marco-fiset / flute example snippets
$validator = new Validator();
$validator->rule_for('first_name')->max_length(100);
$p = new Person('John');
$result = $validator->validate($p);
if ($result->valid()) {
echo 'Valid!';
}
// The naming is very important here. More on that later.
class NotEmptyRule extends Rule // We must extend the Rule abstract class
{
//We override the condition function to run our own validation logic
public function condition($value)
{
// The $value variable contains the value we need to validate.
// For this particular case, it is considered valid if it is
// not equal to the empty string.
return $value !== '';
}
}
// Create an instance of the validator
$v = new Validator();
$v->rule_for('first_name')->not_empty();
class MaxLengthRule extends Rule
{
public function condition($value)
{
return strlen($value) <= $this->max_length;
//W-w-w-wait, what!? Where does max_length come from?
}
}
$v = new Validator();
$v->rule_for('first_name')->max_length(100);
class RequiredRule extends Rule
{
public function extend() {
return array(
new NotNullRule(),
new NotEmptyRule()
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.