PHP code example of asko / hird
1. Go to this page and download the library: Download asko/hird 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/ */
asko / hird example snippets
use Askonomm\Hird\Hird;
$fields = ['email' => '[email protected] '];
$rules = ['email' => '}
$hird->setFieldNames(['email' => 'E-mail']);
$hird->addError("My error message goes here");
use Askonomm\Hird\Hird;
$fields = ['email' => '[email protected] '];
$rules = ['email' => 'email'];
$hird = new Hird($fields, $rules);
use Askonomm\Hird\Hird;
$fields = ['password' => 'SuperSecretPassword'];
$rules = ['password' => 'len:10'];
$hird = new Hird($fields, $rules);
use Askonomm\Hird\Hird;
$fields = ['password' => 'SuperSecretPassword'];
$rules = ['password' => '
use Askonomm\Hird\Hird;
$fields = ['date' => '2020-09-17'];
$rules = ['date' => 'date-format:Y-m-d'];
$hird = new Hird($fields, $rules);
use Asko\Hird\Validators\Validator;
class EmailValidator implements Validator
{
public function __construct(
private array $fields, // all fields data
private array $fieldNames, // names of fields
){
}
/**
* Returns a boolean `true` when given `$value` is a valid e-mail
* address. Returns `false` otherwise.
*
* @param mixed $value
* @param mixed $modifier
* @return boolean
*/
public function validate(string $field, mixed $value, mixed $modifier = null): bool
{
return filter_var($value, FILTER_VALIDATE_EMAIL);
}
/**
* Composes the error message in case the validation fails.
*
* @param string $field
* @param mixed $modifier
* @return string
*/
public function composeError(string $field, mixed $modifier = null): string
{
return "${field} is not a valid e-mail address.";
}
}