2017 © Pedro Peláez
 

library k-switch

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

image

lexide/k-switch

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

  • Wednesday, March 7, 2018
  • by downsider
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

K-Switch

A PHP library to switch cases for property, field and element names, (*1)

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., (*2)

K-Switch is a utility library to allow case switching with the minimum of fuss., (*3)

Installation

Via composer OfC!, (*4)

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...), (*5)


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!, (*6)

The Versions

07/03 2018

dev-develop

dev-develop

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

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Danny Smart

02/03 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Danny Smart

02/03 2018

1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Development Requires

by Danny Smart