crysalead/inflector
Composer 安装命令:
composer require crysalead/inflector
包简介
Inflector Library
关键字:
README 文档
README
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 crysalead/inflector 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Czech inflection library
GOintegro Inflector Lib
Fork of original staticall/petrovich-php repository, with testing, PHP8 support and minor improvements
Склонение по падежам на русском, украинском и казахском языках, расстановка ударений в текстах - PHP-клиент для API morpher.ru.
A library that can inflect strings to many formats
Library for inflecting Russian and Ukrainian Names. Fork of http://namecaselib.com/
统计信息
- 总下载量: 28.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 14
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-28