1. Go to this page and download the library: Download bloise/flunt-php 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/ */
bloise / flunt-php example snippets
final class CPF extends Notifiable
{
...
}
$cpf = new CPF('012.345.678-90');
$cpf->addNotification("CPF", "Invalid document");
if($cpf->isValid())
...
final class CPF extends Notifiable
{
private readonly string $document;
public function __construct(string $document)
{
$this->setDocument($document);
$this->addNotifications(
(new CPFContract)
->hasMinLen($this->document, 'CPF', 'Invalid length')
->validFormat($this->document, 'CPF', 'Invalid format')
->validDocument($this->document, 'CPF', 'Invalid document')
);
}
}
final class CPFContract extends Contract
{
public function hasMinLen(string $cpf, string $property, string $message): self {
if (strlen($cpf) != 11) {
$this->notifications[$property][] = $message;
}
}
public function validFormat(string $cpf, string $property, string $message): self {...}
public function validDocument(string $cpf, string $property, string $message): self {...}
}