20steps / commons-ensure-bundle
Symfony bundle with static helper functions for checking coding pre-/post-conditions
Installs: 1 289
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- doctrine/annotations: @dev
- symfony/framework-bundle: ~2.3|~3.0|~4.0
This package is not auto-updated.
Last update: 2024-12-21 16:36:17 UTC
README
About
The 20steps Commons Ensure Bundle contains static helper functions for checking coding pre-/post-conditions. The check helps to fail early with a EnsureException in the case of missmatched assertions with a meaningful sprintf format message. In comparison to PHP's assert() command, the ensure checks are always enabled.
The 20steps Commons Ensure Bundle is licensed under the LGPL license version 3.0 (http://www.gnu.org/licenses/lgpl-3.0.html).
Installation
- Add the bundle to your composer.json and download a matching version by calling
composer require 20steps/common-ensure-bundle
Prerequisite: Install Composer, the dependency manager used by modern PHP applications.
Usage
The following code shows some simple method call using the Ensure Bundle.
<?php
use twentysteps\Commons\EnsureBundle\Ensure;
class Foo {
private $name;
public function bar($entityName, $num) {
$this->name = Ensure::isNotEmpty($entityName, 'entityName must not be empty');
Ensure::isGreaterThan(0, $num, 'num must be positive for entityName [%s]', $entityName);
// do some stuff...
}
}
Authors
- Marc Ewert marc.ewert@20steps.de
- Helmut Hoffer von Ankershoffen hhva@20steps.de