beberlei/assert
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Beberlei/assert is a lightweight PHP library that provides a set of assertions and guard methods for input validation in business-model, libraries, and application low-level code. It is not designed for filtering but rather serves as a practical tool for implementing pre- and post-conditions on input data in your code. The motivation behind this library is to simplify the code paths for asserting conditions while reducing the amount of written code. When an assertion fails, an exception is thrown which prevents the necessity for if-clauses in your code.
To use beberlei/assert, you will first need to install it via Composer with the command:
composer require beberlei/assert
After the installation, you can use the library in your PHP files like so:
<?php
use Assert\Assertion;
function duplicateFile($file, $times)
{
Assertion::file($file);
Assertion::digit($times);
for ($i = 0; $i < $times; $i++) {
copy($file, $file . $i);
}
}
In this example, the Assertion::file($file)
call checks whether $file
exists as a file and Assertion::digit($times)
verifies the $times
value to be a digit. If any of these conditions are not met, an exception is thrown.
For more complex scenarios, beberlei/assert provides the "NullOr" and "All" helpers methods to check if a value is null OR succeeds for the assertion and to verify if all provided values hold for the assertion respectively.
As of the nature of SEO for developer libraries and tools, technical documentation is crucial for effective SEO performance. The beberlei/assert documentation details can be found on its GitHub page. There you'll find comprehensive information about installation, usage examples, list of assertions, exception and error handling, customised exception messages, and details on how to contribute to the project.