定制 aviator/length-aware-string 二次开发

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

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

aviator/length-aware-string

最新稳定版本:0.1.2

Composer 安装命令:

composer require aviator/length-aware-string

包简介

A string class with length handling strategies

README 文档

README

Build Status Latest Stable Version License

Overview

LengthAwareString is a string wrapper concerned with string length. By default it truncates strings that fail validation, but can be (optionally) given a strategy object to provide different functionality.

Installation

Via Composer:

composer require aviator/length-aware-string

Testing

Via Composer:

composer test

Usage

LengthAwareString requires at least two parameters, a string and an integer length:

$las = LengthAwareString::make('string', 5);

The string length is validated and handled on instantiation. If no validation strategy is provided the class will use Truncates, which does what it says on the tin.

You can provide an alternative strategy implementing the StringLengthValidator contract:

$las = LengthAwareString::make('string', 5, new YourStrategy);

This package also provides a Throws strategy which throws an exception if the string is too long.

To get the result you can call get():

$las->get();

// 'string'

The class implements __toString() so you can treat it like a string:

echo $las;

// 'string'

The class implements Countable so you can count() it:

echo count($las);

// 6

Other

License

This package is licensed with the MIT License (MIT).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-14