定制 borisguery/inflexible 二次开发

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

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

borisguery/inflexible

Composer 安装命令:

composer require borisguery/inflexible

包简介

Collection of Inflectors for string, date, numbers, etc.

README 文档

README

Table of contents

  1. Description
  2. Installation
  3. Usage
  4. Available inflectors
  5. Datetime 1. Relative
  6. Number 1. HumanByte 2. Ordinalize 3. Shorten 4. Textualize
  7. String 1. Camelize 2. Denamespace 3. Humanize 4. NamespaceOnly 5. Slugify
  8. Run the test
  9. Contributing
  10. Requirements
  11. Authors
  12. License

Description

Inflexible aims to gather a collection of commonly used Inflectors into a single lib.

Installation

Using Composer, just $ composer require borisguery/inflexible package or:

{
  "require": {
    "borisguery/inflexible": "dev-master"
  }
}

Usage

Available inflectors

Datetime

Relative

Convert a DateTime object or a number of seconds into the most fitted unit:

Inflexible::relativeDatetime(86400);

Returns

array(
    1,
    'day'
)

You may also want to get the relative datetime from a given date:

Inflexible::relativeDatetime(new DateTime('2012-01-10'), new DateTime('2012-01-17'));

Returns

array(
    1,
    'week'
)

The available units are:

  • second
  • minute
  • hour
  • day
  • week
  • month
  • year

Number

HumanByte

Convert bytes to an human readable representation to the most fitted unit:

Inflexible::humanByte(1024);
// 1.00 KB
Inflexible::humanByte(1048576);
// 1.00 MB
Inflexible::humanByte(1073741824);
// 1.00 GB

You may also provided an optional precision as a second argument (default to 2)

Ordinalize

Converts number to its ordinal English form:

Inflexible::ordinalize(1);
// 1st
Inflexible::ordinalize(13);
// 13th
Shorten

Formats a number using the SI units (k, M, G, etc.):

Inflexible::shorten(100);
// array(100, null)
// No units for number < 1000
Inflexible::shorten(1523);
// 1k
Textualize

Returns the textual representation of a number

Inflexible::textualize(1025433);
// One Million, Twenty Five Thousand, Four Hundred and Thirty Three

String

Camelize

Converts a word like "foo_bar" to "FooBar". It also removes non-alphanumeric characters:

Inflexible::camelize('foo_bar');
// FooBar
Denamespace

Returns only the class name

Inflexible::denamespace('\Foo\Bar\Baz');
// Baz
Humanize

Converts CamelCased word and underscore to space to return a readable string:

Inflexible::humanize('foo_bar');
// Foo Bar
Inflexible::humanize('FooBar');
// Foo Bar
NamespaceOnly

Returns the namespace of a fully qualified class name:

Inflexible::namespaceOnly('\Foo\Bar\Baz');
// Foo\Bar
Slugify

Slugify a string:

Inflexible::namespaceOnly('lo\rem ipsum do|or sid amet||| #\`[|\" 10 .');
// lo-rem-ipsum-do-or-sid-amet-10

You may optionally set the separator, a max length or decide to whether lower the case:

Inflexible::slugify(
    'LoRem ipsum do|or sid amet||| #\`[|\" 10 .',
    array(
        'maxlength' => 4,
        'lowercase' => true,
        'separator' => '_'
    )
);
// lore

Run the test

First make sure you have installed all the dependencies, run:

$ composer install --dev

then, run the test from within the root directory:

$ phpunit

Contributing

  1. Take a look at the list of issues.
  2. Fork
  3. Write a test (for either new feature or bug)
  4. Make a PR

Requirements

  • PHP 5.3+

Authors

Boris Guéry - guery.b@gmail.com - http://twitter.com/borisguery - http://borisguery.com

License

Inflexible is licensed under the WTFPL License - see the LICENSE file for details

borisguery/inflexible 适用场景与选型建议

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

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

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

围绕 borisguery/inflexible 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 19
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: WTFL
  • 更新时间: 2013-01-18