didanurwanda/inflector-php
Composer 安装命令:
composer require didanurwanda/inflector-php
包简介
A lightweight PHP utility for smart word transformations – from singular to plural, snake_case to camelCase, and everything in between. Fully compatible with PHP 7.1 through 8.4.
README 文档
README
A lightweight PHP utility for smart word transformations – from singular to plural, snake_case to CamelCase, and everything in between. Fully compatible with PHP 7.1 through 8.4.
Note:
This library is a PHP port of the popular JavaScript library inflector-js, bringing similar functionality for smart word transformations such as singular/plural conversion and case formatting.
Installation
Install via Composer:
composer require didanurwanda/inflector-php
Or include manually:
require_once 'src/Inflector.php';
How to Use
use Inflector\Inflector; echo Inflector::camelize('message_properties');
API
pluralize
public static function pluralize(string $str, string $plural = null): string
Returns the plural form of a string.
Example:
Inflector::pluralize('person'); // people Inflector::pluralize('Hat'); // Hats Inflector::pluralize('person', 'persons'); // persons Inflector::pluralize('person', 'guys'); // guys
singularize
public static function singularize(string $str, string $singular = null): string
Example:
Inflector::singularize('people'); // person Inflector::singularize('octopi'); // octopus Inflector::singularize('hats'); // hat Inflector::singularize('guys', 'person'); // person
camelize
public static function camelize(string $str, bool $lowFirstLetter = false): string
Example:
Inflector::camelize('message_properties'); // MessageProperties Inflector::camelize('message_properties', true); // messageProperties
underscore
public static function underscore(string $str): string
Example:
Inflector::underscore('MessageProperties'); // message_properties Inflector::underscore('messageProperties'); // message_properties
humanize
public static function humanize(string $str, bool $lowFirstLetter = false): string
Example:
Inflector::humanize('message_properties'); // Message properties Inflector::humanize('messageProperties', true); // message properties
capitalize
public static function capitalize(string $str): string
Example:
Inflector::capitalize('message properties'); // Message properties Inflector::capitalize('message_properties'); // Message_properties
dasherize
public static function dasherize(string $str): string
Example:
Inflector::dasherize('message properties'); // message-properties Inflector::dasherize('message_properties'); // message-properties
camel2words
public static function camel2words(string $str, bool $allFirstUpper = false): string
Example:
Inflector::camel2words('message_properties'); // Message Properties Inflector::camel2words('message properties'); // Message Properties Inflector::camel2words('Message_propertyId', true); // Message Property Id
demodulize
public static function demodulize(string $str): string
Example:
Inflector::demodulize('Message::Bus::Properties'); // Properties
tableize
public static function tableize(string $str): string
Example:
Inflector::tableize('MessageBusProperty'); // message_bus_properties
classify
public static function classify(string $str): string
Example:
Inflector::classify('message_bus_properties'); // MessageBusProperty
foreignKey
public static function foreignKey(string $str, bool $dropIdUbar = false): string
Example:
Inflector::foreignKey('MessageBusProperty'); // message_bus_property_id Inflector::foreignKey('MessageBusProperty', true); // message_bus_propertyid
ordinalize
public static function ordinalize(string $str): string
Example:
Inflector::ordinalize('the 1 pitch'); // the 1st pitch Inflector::ordinalize('1'); // 1st Inflector::ordinalize('2'); // 2nd Inflector::ordinalize('3'); // 3rd Inflector::ordinalize('4'); // 4th
Author
Created and maintained by Dida Nurwanda
didanurwanda@gmail.com
License
This project is licensed under the MIT. See the LICENSE file for more details.
didanurwanda/inflector-php 适用场景与选型建议
didanurwanda/inflector-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「inflector」 「camelcase」 「snakecase」 「plural」 「singular」 「string manipulation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 didanurwanda/inflector-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 didanurwanda/inflector-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 didanurwanda/inflector-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tiny library to handle words case transformation
Simple library to handle words case transformation from array keys
DrevOps PHP_CodeSniffer rules: enforce consistent naming (snakeCase or camelCase) for variables and parameters, PHPUnit data provider conventions.
Utils Library for every day
Simple PHP Inflector
PHP StringHelper is a small library that can perform string manipulation.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-18