承接 didanurwanda/inflector-php 相关项目开发

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

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

didanurwanda/inflector-php

最新稳定版本:v1.0.2

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.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-18