campanda / commons-ensure-bundle
Symfony 扩展包,提供用于检查编码前/后条件的静态辅助函数
v1.0.10
2018-11-10 08:35 UTC
Requires
- doctrine/annotations: @dev
- symfony/framework-bundle: ~2.3|~3.0|~4.0
README
关于
Campanda Commons Ensure Bundle 包含用于检查编码前/后条件的静态辅助函数。检查有助于在断言不匹配的情况下尽早失败,并使用有意义的 sprintf 格式消息抛出 EnsureException。与 PHP 的 assert() 命令相比,确保检查始终启用。
Campanda Commons Ensure Bundle 使用 LGPL 许可协议版本 3.0 许可(https://gnu.ac.cn/licenses/lgpl-3.0.html)。
安装
- 将此扩展包添加到 composer.json 中,并通过以下命令下载匹配的版本:
composer require campanda/common-ensure-bundle
前提条件:安装 Composer,这是现代 PHP 应用程序使用的依赖管理器。
用法
以下代码展示了使用 Ensure Bundle 的简单方法调用。
<?php
use campanda\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...
}
}
作者
- Marc Ewert marc.ewert@20steps.de
- Helmut Hoffer von Ankershoffen hhva@campanda.com