定制 talesoft/tale-inflector 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

talesoft/tale-inflector

Composer 安装命令:

composer require talesoft/tale-inflector

包简介

A library that can inflect strings to many formats

README 文档

README

Packagist License CI Coverage

Tale Inflector

What is Tale Inflector?

Tale inflector bends strings into different naming styles. A common use-case would be the converting of class-names or property-names to table-names or titles to slugs for URLs.

It can also generate the plural or singular of a string or ordinalize numbers.

Installation

composer require talesoft/tale-inflector

Usage

use Tale\Inflector;

$inflector = new Inflector();

//Table generation
$inflector->inflect('ProductAttribute', ['tableize', 'pluralize']); //product_attributes
$inflector->inflect('someProperty', ['tableize']); //some_property

//Canonicalization / slugs
$inflector->inflect('Some title I inserted', ['canonicalize']); //some-title-i-inserted
$inflector->inflect('Was höre ich da?', ['canonicalize']); //was-hore-ich-da

//Or just use the static methods for quick access
Inflector::canonicalize('Some random title'); //some-random-title

Available strategies/static methods

camelize

Tale\Inflector\Strategy\CamelCaseStrategy

some Random string = SomeRandomString

dasherize

Tale\Inflector\Strategy\DashRejoinStrategy

some Random string = some-Random-string

canonicalize

Tale\Inflector\Strategy\KebabCaseStrategy

some Random string = some-random-string

variableize

Tale\Inflector\Strategy\LowerCamelCaseStrategy

some Random string = someRandomString

constantize

Tale\Inflector\Strategy\MacroCaseStrategy

some Random string = SOME_RANDOM_STRING

tableize

Tale\Inflector\Strategy\SnakeCaseStrategy

some Random string = some_random_string

underscorize

Tale\Inflector\Strategy\UnderscoreRejoinStrategy

some Random string = some_Random_string

humanize

Tale\Inflector\Strategy\UppercaseWordsStrategy

some Random string = Some Random String

ordinalize

Tale\Inflector\Strategy\NumberOrdinalStrategy

1 = 1st
12 = 12th
23 = 23rd

pluralize

Tale\Inflector\Strategy\MacroCaseStrategy

rabbit = rabbits
car = cars
house = houses

singularize

Tale\Inflector\Strategy\MacroCaseStrategy

rabbits = rabbit
cars = car
houses = house

Roll your own

use Tale\Inflector\StrategyInterface;

class MyInflectionStrategy implements StrategyInterface
{
   public function inflect(string $string): string
   {
       return "!! {$string} !!";
   }
}

$inflector->inflect('Test', [MyInflectionStrategy::class]); //!! Test !!

You can register your own short names

use Tale\Inflector\StrategyInterface;

class MyInflectionStrategy implements StrategyInterface
{
    public function inflect(string $string): string
    {
        return "!! {$string} !!";
    }
}

$inflector->addNamedStrategy('exlamize', MyInflectionStrategy::class);
$inflector->inflect('House', ['pluralize', 'exclamize']); //!! Houses !!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固