PHP code example of quillstack / validator-interface
1. Go to this page and download the library: Download quillstack/validator-interface 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/ */
quillstack / validator-interface example snippets
use Quillstack\ValidatorInterface\ValidatorInterface;
final class HostValidator implements ValidatorInterface
{
public function __construct(private readonly string $host)
{
}
public function validate(): bool
{
if (filter_var($this->host, FILTER_VALIDATE_DOMAIN) === false) {
throw new UnknownHostException("Not a host: {$this->host}");
}
return true;
}
}
use Quillstack\ValidatorInterface\ValidationExceptionInterface;
final class UnknownHostException extends UriException implements ValidationExceptionInterface
{
}
try {
$validator->validate();
} catch (ValidationExceptionInterface $exception) {
// What was given is wrong — not the code that was given it.
}