campanda / commons-ensure-bundle

Symfony 扩展包,提供用于检查编码前/后条件的静态辅助函数

安装数 2,293

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 1

类型:symfony-bundle

v1.0.10 2018-11-10 08:35 UTC

This package is not auto-updated.

Last update: 2024-09-22 12:40:09 UTC


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)。

安装

  1. 将此扩展包添加到 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...
    }
}

作者

赞助商

Campanda GmbHe