talira

Assert (beberlei/assert)

Thin assertion library for input validation in PHP business models and libraries

open sourceBSD-2-Clausefree

Assert is Benjamin Eberlei's PHP library of assertions and guard methods for validating input (not filtering it) in business models, libraries and low-level application code: each check, such as Assertion::notEmpty() or Assertion::digit(), throws an exception when it fails, which removes if-clauses from your code and implements pre- and post-conditions. It's deliberately low-level and fast, without the objects, locales and translations of Symfony's or Zend's validators. It has a long list of assertions, nullOr and all helpers, a fluent Assert::that() chain, lazy assertions that collect every failure into one exception, custom exception messages and your own assertion class.

Problems it solves

  • validate method arguments in my PHP domain model without writing if statements everywhere
  • check pre-conditions in a PHP library and throw a clear exception
  • collect every validation error for a value at once in PHP

Features

  • static assertion methods that throw on failure
  • nullOr and all helpers
  • fluent Assert::that() chains
  • lazy assertions that report every failure at once
  • custom exception messages and your own assertion class

Alternatives

The same job

These do what Assert (beberlei/assert) does.

  1. Webmozart Assert Assertions to validate PHP method input and output with clear error messages
  2. Respect\Validation Fluent validation engine for PHP with more than 150 validators

Compare Assert (beberlei/assert) with the top 3