jaapoost/fetch-php-inflector

PHP Inflector,从Rails移植过来

v1.0.0 2014-04-10 19:13 UTC

This package is not auto-updated.

Last update: 2024-09-10 17:55:00 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