chroma-x/string-builder 问题修复 & 功能扩展

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

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

chroma-x/string-builder

Composer 安装命令:

composer require chroma-x/string-builder

包简介

A string builder library providing different string methods written in PHP.

README 文档

README

Build Status Test Coverage Dependency Status SensioLabs Insight Code Climate Latest Stable Version Total Downloads License

A basic string builder library providing different string methods written in PHP.

Installation

{
   	"require": {
        "chroma-x/string-builder": "~1.0"
    }
}

Usage

Autoloading and namesapce

require_once('path/to/vendor/autoload.php');

Building and modifying a string

use ChromaX\StringBuilder\StringBuilder;

$builder = new StringBuilder('rolod muspi meroL');
$builder
	->reverse()
	->append(' sit amet, consetetur')
	->append(12)
	->append(false)
	->prepend('b')
	->append(true)
	->insert(1, 'qäs')
	->replace(6, 2, 'wertz')
	->setCharAt(4, '2')
	->delete(0, 2)
	->delete(40)
	->deleteCharAt(3);

$result = $builder->build();
fwrite(STDOUT, ' 1. Built string                                          ' . $result . PHP_EOL);

$result = $builder->buildSubstring(5, 2);
fwrite(STDOUT, ' 2. Built substring                                       ' . $result . PHP_EOL);

$result = $builder->buildSubstring(5);
fwrite(STDOUT, ' 3. Built substring                                       ' . $result . PHP_EOL);

$result = $builder->charAt(5);
fwrite(STDOUT, ' 4. Character at position 5                               ' . $result . PHP_EOL);

$result = $builder->firstChar();
fwrite(STDOUT, ' 5. First character                                       ' . $result . PHP_EOL);

$result = $builder->lastChar();
fwrite(STDOUT, ' 6. Last character                                        ' . $result . PHP_EOL);

will output the following

 1. Built string                                          ä2wertzem ipsum dolor sit amet, conset
 2. Built substring                                       rt
 3. Built substring                                       rtzem ipsum dolor sit amet, conset
 4. Character at position 5                               r
 5. First character                                       ä
 6. Last character                                        t

Getting string properties

$result = $builder->length();
fwrite(STDOUT, ' 7. String length                                         ' . $result . PHP_EOL);

$result = $builder->size();
fwrite(STDOUT, ' 8. Number of bytes                                       ' . $result . PHP_EOL);

$result = $builder->indexOf('e');
fwrite(STDOUT, ' 9. First occurence of "e"                                ' . $result . PHP_EOL);

$result = $builder->indexOf('e', 5);
fwrite(STDOUT, '10. First occurence of "e" after position 5               ' . $result . PHP_EOL);

$result = $builder->lastIndexOf('e');
fwrite(STDOUT, '11. Last occurence of "e"                                 ' . $result . PHP_EOL);

$result = $builder->lastIndexOf('e', 5);
fwrite(STDOUT, '12. Last occurence of "e" before the 5th last character   ' . $result . PHP_EOL);

$result = $builder->contains('ipsum');
fwrite(STDOUT, '13. Whether the string contains "ipsum"                   ' . $result . PHP_EOL);

will output the following

 7. String length                                         38
 8. Number of bytes                                       39
 9. First occurence of "e"                                4
10. First occurence of "e" after position 5               8
11. Last occurence of "e"                                 37
12. Last occurence of "e" before the 5th last character   29
13. Whether the string contains "ipsum"                   <TRUE>

Exception handling

All methods throw an \InvalidArgumentException if misconfigured except indexOf and lastIndexOf wich return null if the given subtring is not contained by the string to build.

use ChromaX\StringBuilder\StringBuilder;

try {
	$builder = new StringBuilder();

	$result = $builder->indexOf('a');
	fwrite(STDOUT, '1. Result                 ' . $result . PHP_EOL);

	$result = $builder->lastIndexOf('a');
	fwrite(STDOUT, '2. Result                 ' . $result . PHP_EOL);

	$result = $builder->charAt(10);
	fwrite(STDOUT, '3. Result                 ' . $result . PHP_EOL);

} catch (\InvalidArgumentException $exception) {
	fwrite(STDERR, 'Exception with message    ' . $exception->getMessage() . PHP_EOL);
}

will output the following

1. Result                 <NULL>
2. Result                 <NULL>
Exception with message    Position invalid

Contribution

Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document.

License

PHP String Builder is under the MIT license.

chroma-x/string-builder 适用场景与选型建议

chroma-x/string-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.38k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「builder」 「string」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 chroma-x/string-builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 chroma-x/string-builder 我们能提供哪些服务?
定制开发 / 二次开发

基于 chroma-x/string-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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