承接 tleckie/enum 相关项目开发

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

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

tleckie/enum

Composer 安装命令:

composer require tleckie/enum

包简介

PHP Enum. One advantage over using class constants is to be able to use an enum as a parameter type

README 文档

README

Latest Version on Packagist Scrutinizer Code Quality Build Status Total Downloads Code Intelligence Status

Enumerator in php

Installation

You can install the package via composer:

composer require tleckie/enum

Usage

Extends Enum class and create your own type.

<?php

/**
 * Class Vehicle
 *
 * @method static Vehicle CAR()
 * @method static Vehicle MOTORCYCLE()
 * @method static Vehicle BIKE()
 * @method static Vehicle TRICYCLE()
 * 
 * @author Teodoro Leckie Westberg <teodoroleckie@gmail.com>
 */
class Vehicle extends Enum 
{
    public const CAR = 1;
    public const MOTORCYCLE = 2;
    public const BIKE = 3;
    public const TRICYCLE = 4;
}

$vehicle = new Vehicle(3);

// Dynamic static methods available
$vehicle::CAR();           // new Vehicle(1)
$vehicle::MOTORCYCLE();    // new Vehicle(2)
$vehicle::BIKE();          // new Vehicle(3)
$vehicle::TRICYCLE();      // new Vehicle(4)
.
.
.
Vehicle::CAR();           // new Vehicle(1)
Vehicle::MOTORCYCLE();    // new Vehicle(2)
Vehicle::BIKE();          // new Vehicle(3)
Vehicle::TRICYCLE();      // new Vehicle(4)
public function edit(Vehicle $vehicle){
    //...
}

$object->edit(Vehicle::CAR());
$vehicle = new Vehicle(3);

$vehicle->getValue();  // int(3)
$vehicle->getKey();    // "BIKE"

getValues():

$vehicle = new Vehicle(3);
$vehicle->getValues(); // [1,2,3,4]

getKeys():

$vehicle = new Vehicle(3);
$vehicle->getKeys();    //["CAR","MOTORCYCLE","BIKE","TRICYCLE"]

toArray():

$vehicle = new Vehicle(3);
$vehicle->toArray();   //["CAR" => 1,"MOTORCYCLE" => 2,"BIKE" => 3,"TRICYCLE" => 4]

Cast string

(string) Vehicle::MOTORCYCLE();             // "2"
(string) new Vehicle(3);                    // "3"
(string) new Vehicle( Vehicle::TRICYCLE() );// "4"
(string) new Vehicle( new Vehicle(1) );     // "1"

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固