my-gov/myssm

一个解析和验证马来西亚商业注册号(BRN)的库。此库确保符合SSM格式标准,准确提取实体类型和注册年份等组件,并验证BRN的完整性。

1.0.6 2024-08-09 06:25 UTC

This package is auto-updated.

Last update: 2024-09-09 06:36:33 UTC


README

简单的MySSM商业注册号和验证器。

安装

composer require my-gov/myssm

基本用法

使用MySSM BRN解析器从给定的商业注册号中检索基本信息。

require 'vendor/autoload.php';

use MyGOV\MySSM\BRN;
use MyGOV\MySSM\Exceptions\ParseBRNException;
use MyGOV\MySSM\Exceptions\InvalidBRNException;
use MyGOV\MySSM\Exceptions\InvalidBRNFormatException;
use MyGOV\MySSM\Format\Enums\EntityCode;
use Throwable;

try {
    $brn = BRN::parse('201901000005 (1312525-A)');
    if ($brn->isValid()) {
        echo $brn;                                      // 201901000005 (1312525-A)
        echo $brn->format2019;                          // 201901000005
        echo $brn->format2019->isValid();               // true
        echo $brn->format2019->getYear();               // 2019
        echo $brn->format2019->getEntityCode();         // 01
        echo $brn->format2019->getEntityTypeName();     // Local Companies
        echo $brn->format2019->getSequenceNumber();     // 000005
        echo $brn->format2019->is(EntityCode::Business);// false

        echo $brn->classic;                             // 1312525-A
        echo $brn->classic->isValid();                  // true
        echo $brn->classic->getSequenceNumber();        // 1312525
        echo $brn->classic->getCheckDigit();            // A
        echo $brn->classic->is(EntityCode::Business);   // false
    }

    $brn = BRN::parse('SA0173178-P/ 202003000005');
    if ($brn->isValid()) {
        echo $brn;                                      // 202003000005 (SA0173178-P)
        echo $brn->format2019;                          // 202003000005
        echo $brn->format2019->isValid();               // true
        echo $brn->format2019->getYear();               // 2020
        echo $brn->format2019->getEntityCode();         // 03
        echo $brn->format2019->getEntityTypeName();     // Business (ROB)
        echo $brn->format2019->getSequenceNumber();     // 000005
        echo $brn->format2019->is(EntityCode::Business);// true

        echo $brn->classic;                             // SA0173178-P
        echo $brn->classic->isValid();                  // true
        echo $brn->classic->getSequenceNumber();        // SA0173178
        echo $brn->classic->getCheckDigit();            // P
        echo $brn->classic->is(EntityCode::Business);   // true
    }

    $brn = BRN::parse('SA0173178-P');
    if ($brn->isValid()) {
        echo $brn;                                      // SA0173178-P
        echo $brn->format2019;                          // null
        echo $brn->format2019->isValid();               // false
        echo $brn->format2019->getYear();               // null
        echo $brn->format2019->getEntityCode();         // null
        echo $brn->format2019->getEntityTypeName();     // null
        echo $brn->format2019->getSequenceNumber();     // null
        echo $brn->format2019->is(EntityCode::Business);// false

        echo $brn->classic;                             // SA0173178-P
        echo $brn->classic->isValid();                  // true
        echo $brn->classic->getSequenceNumber();        // SA0173178
        echo $brn->classic->getCheckDigit();            // P
        echo $brn->classic->is(EntityCode::Business);   // true
    }

    $brn = BRN::parse('3178-Q');
    if ($brn->isValid()) {
        echo $brn;                                          // 0003178-Q
        echo $brn->format2019;                              // null
        echo $brn->format2019->isValid();                   // false
        echo $brn->format2019->getYear();                   // null
        echo $brn->format2019->getEntityCode();             // null
        echo $brn->format2019->getEntityTypeName();         // null
        echo $brn->format2019->getSequenceNumber();         // null
        echo $brn->format2019->is(EntityCode::Business);    // false

        echo $brn->classic;                                         // 3178-P
        echo $brn->classic->isValid();                              // true
        echo $brn->classic->leadingZeros();                         // 0003178-P
        echo $brn->classic->getSequenceNumber();                    // 3178
        echo $brn->classic->leadingZeros()->getSequenceNumber();    // 0003178  show leading zeros.
        echo $brn->classic->getCheckDigit();                        // P
        echo $brn->classic->is(EntityCode::Business);               // false
    }
} catch (Throwable $throwable) {
    echo $throwable->getMessage();
}

启用异常

exception 设置为 true 以启用 异常

require 'vendor/autoload.php';

use MyGOV\MySSM\BRN;

try {
    $brn = BRN::parse('201901003209 (000184266S)', exception: true);

    if ($brn->isValid()) {
        echo $brn->classic->getSequenceNumber();   // 000184266
        echo $brn->classic->getCheckDigit();       // S
    } else {
        echo $brn->classic->getSequenceNumber();   // null
        echo $brn->classic->getCheckDigit();       // null
    }
} catch (ParseBRNException | InvalidBRNException | InvalidBRNFormatException | Throwable $throwable) {
    echo $throwable->getMessage();
}

商业注册号(BRN)生成器

生成一个随机的商业注册号。

require 'vendor/autoload.php';

use MyGOV\MySSM\Exceptions\GenerateBRNException;
use MyGOV\MySSM\Format\Enums\EntityCode;
use MyGOV\MySSM\BRN;

try {
    $brn = BRN::make();
    if ($brn->isValid()) {
        echo $brn;                                      // 202003000005 (SA0173178-P)
        echo $brn->format2019;                          // 202003000005
        echo $brn->format2019->isValid();               // true
        echo $brn->format2019->getYear();               // 2020
        echo $brn->format2019->getEntityCode();         // 03
        echo $brn->format2019->getEntityTypeName();     // Business (ROB)
        echo $brn->format2019->getSequenceNumber();     // 000005
        echo $brn->format2019->is(EntityCode::Business);// true

        echo $brn->classic;                             // SA0173178-P
        echo $brn->classic->isValid();                  // true
        echo $brn->classic->getSequenceNumber();        // SA0173178
        echo $brn->classic->getCheckDigit();            // P
        echo $brn->classic->is(EntityCode::Business);   // true
    }
} catch(GenerateBRNException | Throwable Throwable) {
    echo $throwable->getMessage();
}

生成带有注册年份的BRN。

$brn = BRN::make(year: 2010);
if ($brn->isValid()) {
    echo $brn;                                      // 201001000005 (SA0173178-P)
    echo $brn->format2019;                          // 201001000005
    echo $brn->format2019->isValid();               // true
    echo $brn->format2019->getYear();               // 2010
    echo $brn->format2019->getEntityCode();         // 01
    echo $brn->format2019->getEntityTypeName();     // Local Companies
    echo $brn->format2019->getSequenceNumber();     // 000005
    echo $brn->format2019->is(EntityCode::Business);// false

    echo $brn->classic;                             // SA0173178-P
    echo $brn->classic->isValid();                  // true
    echo $brn->classic->getSequenceNumber();        // SA0173178
    echo $brn->classic->getCheckDigit();            // P
    echo $brn->classic->is(EntityCode::Business);   // false
}

生成ROB BRN。

$brn = BRN::make(entityCode: EntityCode::Business);
if ($brn->isValid()) {
    echo $brn;                                      // 199003000005 (SA0173178-P)
    echo $brn->format2019;                          // 199003000005
    echo $brn->format2019->isValid();               // true
    echo $brn->format2019->getYear();               // 1990
    echo $brn->format2019->getEntityCode();         // 03
    echo $brn->format2019->getEntityTypeName();     // Business (ROB)
    echo $brn->format2019->getSequenceNumber();     // 000005
    echo $brn->format2019->is(EntityCode::Business);// true

    echo $brn->classic;                             // SA0173178-P
    echo $brn->classic->isValid();                  // true
    echo $brn->classic->getSequenceNumber();        // SA0173178
    echo $brn->classic->getCheckDigit();            // P
    echo $brn->classic->is(EntityCode::Business);   // true
}

许可证

Simsoft MyGOV/MySSM 在MIT许可证下发布。有关详细信息,请参阅LICENSE文件。