定制 decodelabs/tightrope 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

decodelabs/tightrope

最新稳定版本:v0.2.0

Composer 安装命令:

composer require decodelabs/tightrope

包简介

Reusable constraints for your PHP classes

README 文档

README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

Reusable constraints for your PHP classes.

Note: With the introduction of properties in PHP8.4, the need for Tightrope has diminished. This package is now deprecated and will not be maintained. You can use the built-in property types and visibility modifiers to achieve similar functionality, without methods.

Installation

composer require decodelabs/tightrope

Usage

Tightrope defines a number of reusable interfaces that represent a property of an object, such as being disableable, readable or requirable:

namespace DecodeLabs\Tightrope;

interface Nullable {
    public function isNullable(): bool;
}

It also supplies a manifest version of each interface along with a trait implementation:

namespace DecodeLabs\Tightrope\Manifest;

use DecodeLabs\Tightrope\Nullable as StaticNullable;

interface Nullable extends StaticNullable {
    public function setNullable(bool $flag): static;
}

You can use these interfaces to define properties of your objects:

namespace My\Project;

use DecodeLabs\Exceptional;
use DecodeLabs\Tightrope\Manifest\Nullable;
use DecodeLabs\Tightrope\Manifest\NullableTrait;

class MyClass implements Nullable {

    use NullableTrait;

    public function doSomething(?string $value): void {
        if(
            !$this->isNullable() &&
            $value === null
        ) {
            throw Exceptional::InvalidArgument(
                message: 'Value cannot be null'
            );
        }

        // ...
    }
}

$myObject = new MyClass();

$myObject->setNullable(true);
$myObject->doSomething(null); // Fine

$myObject->setNullable(false);
$myObject->doSomething(null); // Not fine

Available properties

The following interfaces are currently available:

  • Disableable
  • Immutable
  • Nullable
  • Readable
  • ReadOnlyable
  • Requirable
  • Writable

Licensing

Tightrope is licensed under the MIT License. See LICENSE for the full license text.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固