定制 commandstring/blood 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

commandstring/blood

最新稳定版本:v2.1.1

Composer 安装命令:

composer require commandstring/blood

包简介

A package for handling blood types

README 文档

README

A composer package for bloodtypes (website is in the gui branch)

Installation

composer require commandstring/blood

Usage

Creating Blood

You can either create a blood object with proteins, antibodies, or type

use CommandString\Blood\Blood;
use CommandString\Blood\Enums\BloodType;
use CommandString\Blood\Enums\Protein;

$bloodFromType       = new Blood(BloodType::A_POSITIVE);
$bloodFromProteins   = Blood::fromProteins(Protein::A, Protein::RH);
$bloodFromAntibodies = Blood::fromAntibodies(Antibody::B, Antibody::RH);

Checking compatibility between blood types

use CommandString\Blood\Blood;
use CommandString\Blood\Enums\BloodType;
use CommandString\Blood\Enums\Protein;

$bloodType1 = new Blood(BloodType::A_POSITIVE);
$bloodType2 = new Blood(BloodType::O_NEGATIVE);

$bloodType1->canDonateTo($bloodType2); // false
$bloodType1->canReceiveFrom($bloodType2); // true
$bloodType2->canDonateTo($bloodType1); // true
$bloodType2->canReceiveFrom($bloodType1); // false

Getting Proteins and Antibodies

use CommandString\Blood\Enums\Protein;

/** 
 * @var \CommandString\Blood\Blood $bloodType1 
 * @var Protein[] $proteins
 * @var Protein[] $antibodies
 */
$proteins = $bloodType1->getProteins();
$antibodies = $bloodType1->getAntibodies();

Getting Type

use CommandString\Blood\Enums\BloodType;

/** 
 * @var \CommandString\Blood\Blood $bloodType1 
 * @var BloodType $type
 */
$type = $bloodType1->getType();
$type = $bloodType1->type; 

Example Script

<?php

use CommandString\Blood\Blood;
use CommandString\Blood\Enums\BloodType;

require_once __DIR__ . '/vendor/autoload.php';

const ITEM_PREFIX = "* ";
const H2 = "\n## ";
const H3 = "\n### ";

$forType = static function (BloodType $type): void {
    $blood = new Blood($type);
    echo H2 . "Blood Type: {$blood->getType()->value}\n"; // A+

    echo H3 . "Proteins:\n";
    foreach ($blood->getProteins() as $protein) {
        echo ITEM_PREFIX . "{$protein->value}\n";
    }

    echo H3 . "Antibodies:\n";
    foreach ($blood->getAntibodies() as $antibody) {
        echo ITEM_PREFIX . "{$antibody->value}\n";
    }

    echo H3. "Can Donate To:\n";
    foreach (BloodType::cases() as $type) {
        $toReceive = new Blood($type);

        echo $blood->canDonateTo($toReceive) ? ITEM_PREFIX . "{$toReceive->getType()->value}\n" : '';
    }

    echo H3 . "Can Receive From:\n";
    foreach (BloodType::cases() as $type) {
        $toDonate = new Blood($type);

        echo $blood->canReceiveFrom($toDonate) ? ITEM_PREFIX . "{$toDonate->getType()->value}\n" : '';
    }
};

$divider = "---\n";
foreach (BloodType::cases() as $type) {
    $forType($type);
    echo $divider;
}

Output

Blood Type: A-

Proteins:

  • A

Antibodies:

  • B
  • RH

Can Donate To:

  • A-
  • A+
  • AB-
  • AB+

Can Receive From:

  • A-
  • A+
  • AB-
  • AB+

Is Universal Donor: No

Is Universal Recipient: No

Blood Type: A+

Proteins:

  • A
  • RH

Antibodies:

  • B

Can Donate To:

  • A+
  • AB+

Can Receive From:

  • A+
  • AB+

Is Universal Donor: No

Is Universal Recipient: No

Blood Type: B-

Proteins:

  • B

Antibodies:

  • A
  • RH

Can Donate To:

  • B-
  • B+
  • AB-
  • AB+

Can Receive From:

  • B-
  • B+
  • AB-
  • AB+

Is Universal Donor: No

Is Universal Recipient: No

Blood Type: B+

Proteins:

  • B
  • RH

Antibodies:

  • A

Can Donate To:

  • B+
  • AB+

Can Receive From:

  • B+
  • AB+

Is Universal Donor: No

Is Universal Recipient: No

Blood Type: AB-

Proteins:

  • A
  • B

Antibodies:

  • RH

Can Donate To:

  • AB-
  • AB+

Can Receive From:

  • AB-
  • AB+

Is Universal Donor: No

Is Universal Recipient: No

Blood Type: AB+

Proteins:

  • A
  • B
  • RH

Antibodies:

Can Donate To:

  • AB+

Can Receive From:

  • AB+

Is Universal Donor: No

Is Universal Recipient: Yes

Blood Type: O-

Proteins:

Antibodies:

  • A
  • B
  • RH

Can Donate To:

  • A-
  • A+
  • B-
  • B+
  • AB-
  • AB+
  • O-
  • O+

Can Receive From:

  • A-
  • A+
  • B-
  • B+
  • AB-
  • AB+
  • O-
  • O+

Is Universal Donor: Yes

Is Universal Recipient: No

Blood Type: O+

Proteins:

  • RH

Antibodies:

  • A
  • B

Can Donate To:

  • A+
  • B+
  • AB+
  • O+

Can Receive From:

  • A+
  • B+
  • AB+
  • O+

Is Universal Donor: No

Is Universal Recipient: No

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-17