承接 webservco/constant-value-class 相关项目开发

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

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

webservco/constant-value-class

最新稳定版本:v1.5.1

Composer 安装命令:

composer require webservco/constant-value-class

包简介

A Constant Value Class implementation

关键字:

README 文档

README

A Constant Value Class implementation (enum simulation for PHP 7).

Based on the article "Expressive, type-checked constants for PHP".

Note: Only int and string values are supported.

Example

Constant Value Class

Please see tests/unit/WebServCo/ConstantValueClass/Example.php

Usage

class Shipment
{
    public function send(Type $type): bool
    {
        // ...
    }
}
$shipment = new Shipment();
$shipment->send(Type::import());

// or
$type = 2; // request parameter, user input, etc
$shipment->send(Type::fromValue($type));

// get value (exact type) (eg. for form select)
echo Type::import()->value(); // outputs "1"

// get string representation of value
echo Type::import(); // outputs "1"

// comparison
$import = Type::fromValue(2);
if (Type::import() === $import) {
    // === works as long as the object is created in the current script run,
    // not for example created elsewhere and stored serialized in session.
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-21