Skip to content
Search
Examples

Types

Description

Type validation checks if a value matches the expected type without throwing exceptions. The isValid() method returns true if the value conforms to the type, false otherwise. This is useful for conditional logic, filtering data, or performing pre-flight checks before processing.

Unlike assertions, validation never throws - it's designed for control flow decisions rather than enforcing contracts.


Validate HTML documents. Returns true for valid HTML strings and DOMDocument objects.

Documentation

Code

<?php

declare(strict_types=1);

use function Flow\Types\DSL\type_html;

require __DIR__ . '/vendor/autoload.php';

$validHtml = '<html><body><p>Hello World</p></body></html>';
$simpleHtml = '<p>Simple paragraph</p>';

echo 'Is valid HTML valid? ' . (type_html()->isValid($validHtml) ? 'yes' : 'no') . "\n";
echo 'Is simple HTML valid? ' . (type_html()->isValid($simpleHtml) ? 'yes' : 'no') . "\n";
echo 'Is DOMDocument valid? ' . (type_html()->isValid(new \DOMDocument()) ? 'yes' : 'no') . "\n";
echo 'Is empty string valid? ' . (type_html()->isValid('') ? 'yes' : 'no') . "\n";
Contributors

Built in the open.

Join us on GitHub
scroll back to top