Asf_Ensure


Introduction

Asf_Ensure 条件判断类, 配合 Constants类使用, 如果条件未命中, 中断型输出自定义的错误码 & 错误内容

Constants类是一个特殊的类, 里面必须定义一个静态属性 ErrDescription(暂不支持自定义)

在开启命名空间情况下(asf.use_namespace=1)类名为 Asf\Ensure

Class synopsis

<?php
final class Asf_Ensure
{
    public static void isNull(mixed $data, int $errno [, string $class_name = ''])
    public static void notNull(mixed $data, int $errno [, string $class_name = ''])
    public static void isEmpty(mixed $data, int $errno, [, string $class_name = ''])
    public static void notEmpty(mixed $data, int $errno, [, string $class_name = ''])
    public static void isFalse(mixed $data, int $errno, [, string $class_name = ''])
    public static void notFalse(mixed $data, int $errno, [, string $class_name = ''])
    public static void isTrue(mixed $data, int $errno [, string $class_name = ''])
    public static void out(string $data, int $errno)
}

Examples

Example #1

<?php
use Asf\Ensure;

class Constants
{
    const ERR_TEST_CODE = 500;
    const ERR_USER_CODE = 501;

    public static $ErrDescription = array(
        self::ERR_TEST_CODE => 'This is test default text',
        self::ERR_USER_CODE => 'This is test user text',
    );
}

Ensure::notNull(null, Constants::ERR_TEST_CODE);

Example #2

<?php
use Asf\Ensure;

// Filepath: asf.root_path/library/DefConstants.php
class DefConstants
{
    const ERR_TEST_CODE = 500;

    public static $ErrDescription = array(
        self::ERR_TEST_CODE => 'This is test default text',
    );
}

// Filepath: asf.root_path/modules/api/services/Main.php
class MainService
{
    public function userAction()
    {
        $data = '';
        Ensure::notEmpty($data, Defconstants::ERR_TEST_CODE, 'Defconstants');
    }
}