定制 lexide/k-switch 二次开发

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

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

lexide/k-switch

Composer 安装命令:

composer require lexide/k-switch

包简介

A PHP library to switch cases of a property or element name

README 文档

README

A PHP library to switch cases for property, field and element names

Say what, now?

When dealing with different sources of data, it is often the case that field names will be in one case, typically "snake_case", and PHP classes will use "camelCase" for property names. Mapping between the two is non-trivial to do by hand.

K-Switch is a utility library to allow case switching with the minimum of fuss.

Installation

Via composer OfC!

composer require lexide/k-switch

How to use

Any class that needs to switch cases can use the NameConverterTrait. This trait adds private methods to convert name strings into "StudlyCaps", "camelCase", "snake_case", "dash-case" and any other case that splits words with delimiters (spaces, pipes, etc...)

class Converter {
    use Lexide\KSwitch\NameConverterTrait;
    
    public function convertStudly($string)
    {
        return $this->toStudlyCaps($string);
    }
    
    public function convertCamel($string)
    {
        return $this->toCamelCase($string);
    }
    
    public function convertSnake($string)
    {
        return $this->toSplitCase($string);
    }
    
}



$converter = new Converter();

$converter->convertStudly("aCamelCaseName"); // ACamelCaseName
$studly = $converter->convertStudly("a_snake_case_name"); // returns "ASnakeCaseName"

$converter->convertSnake($studly); // back to "a_snake_case_name"

... and that's it?

Yup! Enjoy!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固