20steps / commons-ensure-bundle
Symfony 扩展包,提供用于检查编码前/后条件的静态辅助函数
v1.0.6
2018-05-07 19:26 UTC
Requires
- doctrine/annotations: @dev
- symfony/framework-bundle: ~2.3|~3.0|~4.0
This package is not auto-updated.
Last update: 2024-09-28 15:29:00 UTC
README
关于
20steps Commons Ensure 扩展包包含用于检查编码前/后条件的静态辅助函数。检查可以帮助在断言不匹配时尽早失败,并使用有意义的 sprintf 格式消息抛出 EnsureException 异常。与 PHP 的 assert() 命令相比,ensure 检查始终启用。
20steps Commons Ensure 扩展包采用 LGPL 许可协议版本 3.0 (https://gnu.ac.cn/licenses/lgpl-3.0.html)。
安装
- 将扩展包添加到 composer.json 文件中,并通过调用以下命令下载匹配的版本
composer require 20steps/common-ensure-bundle
先决条件:安装 Composer,这是现代 PHP 应用程序使用的依赖管理器。
使用方法
以下代码展示了使用 Ensure 扩展包的一些简单方法调用。
<?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...
}
}
作者
- Marc Ewert marc.ewert@20steps.de
- Helmut Hoffer von Ankershoffen hhva@20steps.de