承接 crysalead/inflector 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

crysalead/inflector

Composer 安装命令:

composer require crysalead/inflector

包简介

Inflector Library

关键字:

README 文档

README

Build Status Code Coverage

Inflector is a small library that can perform string transformation like singularization, pluralization, underscore to camel case, titelize words and more. Inflections can be localized.

The Inflector class is prepopulated with english inflections for singularization and pluralization to be ready to use.

Usage

Examples of usage of the inflector with the 'default' locale (i.e english):

use Lead\Inflector\Inflector;

# pluralize

Inflector::pluralize('post');                       // "posts"
Inflector::pluralize('posts');                      // "posts"
Inflector::pluralize('child');                      // "children"
Inflector::pluralize('ContactPerson');              // "ContactPeople"

# singularize

Inflector::singularize('posts');                    // "post"
Inflector::singularize('children');                 // "child"
Inflector::singularize('ContactPeople');            // "ContactPerson"

# transliterate

Inflector::transliterate('の話が出たので大丈夫かなあと'); // "no huaga chutanode da zhang fukanaato"

# slug

Inflector::slug('Foo:Bar & Cie');                   // "Foo-Bar-Cie"
Inflector::slug('Foo:Bar & Cie', '_');              // "Foo_Bar_Cie"

# parameterize

Inflector::parameterize('Foo:Bar & Cie');           // "foo-bar-cie"
Inflector::parameterize('Foo:Bar & Cie', '_');      // "foo_bar_cie"

# camelize

Inflector::camelize('test_field');                  // "TestField"
Inflector::camelize('TEST_FIELD');                  // "TestField"
Inflector::camelize('my_name\space');               // "MyName\Space"

# camelback

Inflector::camelback('test_field');                 // "testField"
Inflector::camelback('TEST_FIELD');                 // "testField"

# underscore

Inflector::underscore('TestField');                 // "test_field"
Inflector::underscore('MyName\Space');              // "my_name\space"
Inflector::underscore('dashed-string');             // "dashed_string"

# dasherize

Inflector::dasherize('underscored_string');         // "underscored_string"

# humanize

Inflector::humanize('employee_salary');             // "Employee salary"
Inflector::humanize('author_id');                   // "Author"

# titleize

Inflector::titleize('man from the boondocks');      // "Man From The Boondocks"
Inflector::titleize('x-men: the last stand');       // "X Men: The Last Stand"
Inflector::titleize('TheManWithoutAPast');          // "The Man Without A Past"
Inflector::titleize('raiders_of_the_lost_ark');     // "Raiders Of The Lost Ark"

#### Examples of usage of custom locales:

namespace inflector\Inflector;

Inflector::pluralize('child');                       // "children"

//Load custom definition for `'zz'` locale using a closure
Inflector::singular('/x$/i', '', 'zz');
Inflector::plural('/([^x])$/i', '\1x', 'zz');

Inflector::singularize('abcdefx', 'zz');             // "abcdef"
Inflector::pluralize('abcdef', 'zz');                // "abcdefx"

If you wan't to use an other language by default for inflections, you can override the 'default' rules directly.

Inflector::reset(true); // Remove all loaded inflection rules.

Inflector::singular('/x$/i', '', 'default');
Inflector::plural('/([^x])$/i', '\1x', 'default');

Inflector::singularize('abcdefx');             // "abcdef"
Inflector::pluralize('abcdef');                // "abcdefx"

Note: you can check spec/fixture for some examples of inflection rules for spanish and french languages.

Requirement

Requires PHP >= 5.4 and the PECL intl extension.

sudo apt-get install php-intl

Installation with Composer

The recommended way to install this package is through Composer. Create a composer.json file and run composer install command to install it:

{
	"require":
	{
		"crysalead/inflector": "~1.0"
	}
}

Testing

The spec suite can be runned with:

cd inflector
composer install
./bin/kahlan

PS: Composer need to be present on your system.

Acknowledgements

Most of the code and documentation was adapted from Ruby On Rails's Inflector.

crysalead/inflector 适用场景与选型建议

crysalead/inflector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.72k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2014 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 28.72k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 14
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-28