承接 elegant-php/types 相关项目开发

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

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

elegant-php/types

最新稳定版本:1.0.0

Composer 安装命令:

composer require elegant-php/types

包简介

PHP types as objects

README 文档

README

tests version downloads license

This package provides the ability to work with types as objects.

Available types:

  • Integer
  • String
  • Float
  • Boolean
  • Array

Installation

composer require elegant-php/types

Usage

Use predefined classes and contracts

final class AuthorizedUser implements User
{
  public function __construct(
    private readonly StringType $name
  ) { }
}

$user = new AuthorizedUser(new DefaultString('my user'));

Implement type contracts

final class UserName extends StringType
{
  public function __construct(
    private readonly string $name
  ) { }

  public function value(): string
  {
    return strtolower($this->name);
  }
}

Compare types

$first = new DefaultString('first');
$second = new DefaultString('first');

var_dump($first->equals($second));

// bool(false)

Type casting

$id = new StringAsInteger('123');

var_dump($id->value());

// int(123)

Release notes

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2024-01-11