leeroy/php-inflector

PHP Inflector,从 Rails 转移而来

1.0.1 2022-11-21 19:48 UTC

This package is auto-updated.

Last update: 2024-09-21 23:26:09 UTC


README

PHP Inflector 库,从 Rails 转移而来

最低要求

安装

使用 PHP Inflector 最简单的方法是通过 Composer 安装

创建或更新 composer.json

{
  "require": {
    "koenpunt/php-inflector": "1.0.*"
  }
}

然后运行 composer install

功能

  • 基本功能

    • singularize
    • pluralize
    • singularize
    • camelize
    • underscore
    • humanize
    • titleize
    • tableize
    • classify
    • dasherize
    • denamespace
    • foreign_key
    • ordinalize
  • 国际化

    • transliterate
    • parameterize

用法

PHP Inflector 以类形式实现,包含静态函数

Inflector::underscore("PhpInflector\Inflector"); # => php_inflector/inflector

PhpInflector\Inflector::parameterize("Ærøskøbing on Water"); # => aeroskobing-on-water

PhpInflector\Inflector::foreign_key("Admin\Post"); # => post_id

PhpInflector\Inflector::denamespace("PhpInflector\Inflector\Inflections"); # => Inflections

PhpInflector\Inflector::dasherize("puni_puni"); # => puni-puni

也可以添加自定义词形变化,如缩写词

PhpInflector\Inflector::inflections(function($inflect){
  $inflect->acronym('RESTful');
});

PhpInflector\Inflector::titleize('RESTfulController'); # => RESTful Controller

更多示例和文档可以在源代码中找到。

贡献

  1. 分支它
  2. 创建你的功能分支(git checkout -b my-new-feature
  3. 提交你的更改(git commit -am 'Added some feature'
  4. 推送到分支(git push origin my-new-feature
  5. 创建新的 Pull Request