ghostwriter/option 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ghostwriter/option

最新稳定版本:2.0.0

Composer 安装命令:

composer require ghostwriter/option

包简介

Provides an Option type implementation for PHP

README 文档

README

GitHub Sponsors Automation Supported PHP Version Downloads

Provides an Option type implementation for PHP.

Installation

You can install the package via composer:

composer require ghostwriter/option

Star ⭐️ this repo if you find it useful

You can also star (????) this repo to find it easier later.

Usage

use Ghostwriter\Option\Exception\NullPointerException;
use Ghostwriter\Option\None;
use Ghostwriter\Option\Some;
use Ghostwriter\Option\Option;

$message = '#BlackLivesMatter';
Option::new($message); // return `Some`

$some = Some::new($message); // return `Some`
echo $some->get(); // prints #BlackLivesMatter

$none = None::new(); // return `None`

// calling the `get` method on `None` will throw `NullPointerException`
echo $none->get(); // throw `NullPointerException`

echo $none->getOr('#BLM'); // prints #BLM

// calling the `new` static method with `null` will return `None`
Option::new(null); // return `None`

// calling the `new` static method with `null will throw `NullPointerException`
Some::new(null); // throws `NullPointerException`

// calling the `new` static method with `None will throw `NullPointerException`
Some::new(None::new()); // throws `NullPointerException`

--- Example

function divide(int $x, int $y): OptionInterface
{
    if ($y === 0) {
        return None::new();
    }

    return Some::new($x / $y);
}

divide(1, 0); // None
divide(1, 1); // Some(1)

Testing

composer test

Credits

Changelog

Please see CHANGELOG.md for more information on what has changed recently.

License

Please see LICENSE for more information on the license that applies to this project.

Security

Please see SECURITY.md for more information on security disclosure process.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固