承接 wgx954418992/php-enum 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

wgx954418992/php-enum

Composer 安装命令:

composer require wgx954418992/php-enum

包简介

The simplest and fastest PHP enumeration, supports `then` matching callback

README 文档

README

简体中文

The simplest and fastest PHP enumeration, supports then matching callback and Specific value

1. composer install

composer require wgx954418992/php-enum

2. demo

<?php

use enum\classier\Enum;

require '../vendor/autoload.php';

/**
 * Class OrderStatus
 * 
 * @warning `Constant values cannot be repeated`
 */
class OrderStatus extends Enum
{

    /**
     * order status wait pay
     */
    public const WAIT_PAY = 'WAIT_PAY';

    /**
     * order status payed
     */
    public const PAYED = 'PAYED';

    /**
     * order status delivering
     */
    public const DELIVERING = 'DELIVERING';

    /**
     * order status complete next status wait comment
     */
    public const COMPLETE = 'COMPLETE';

    /**
     * order status commented
     */
    public const COMMENTED = 'COMMENTED';

    /**
     * Get real value of constant 'WAIT_PAY', it will be called at the time of construction, but not later And the priority is higher than Static Property
     */
    protected function getWaitPay()
    {
        return new class {

            /**
             * @var string
             */
            private $text = "To be paid";

            /**
             * @return string
             */
            public function getText(): string
            {
                return $this->text;
            }
        };
    }

    /**
     * static property
     * @var string[]
     */
    protected static $_PAYED = ['text' => '已支付'];
}

try {
    $status = OrderStatus::i(OrderStatus::WAIT_PAY);

    echo "name: {$status->getName()}" . PHP_EOL;

    echo "value:" . PHP_EOL;

    print_r($status->getValue());

    echo PHP_EOL;

    $status
        ->then(OrderStatus::WAIT_PAY, OrderStatus::PAYED, function () {
            echo 'Hit WAIT_PAY,PAYED' . PHP_EOL;
        })
        ->then(OrderStatus::DELIVERING, function () {
            echo 'Hit DELIVERING' . PHP_EOL;
        })
        ->then(OrderStatus::COMPLETE, function () {
            echo 'Hit COMPLETE' . PHP_EOL;
        })
        ->then(OrderStatus::COMMENTED, function () {
            echo 'Hit COMMENTED' . PHP_EOL;
        })
        ->default(function (){
            echo 'default' . PHP_EOL;
        })
        ->fetch();

} catch (Exception $e) {
    exit($e->getMessage());
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固