Download the PHP package neunerlei/inflection without Composer

On this page you can find all versions of the php package neunerlei/inflection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package inflection

Inflection

The package contains yet another inflector but with a twist. The implementation of the actual inflecting (pluralize and singularize a string) is agnostic to the actual implementation you want to use. By default the inflection is done by the symfony/inflector but you can simply switch to any other inflector using adapter classes.

In addition to that the inflector comes with additional string modification capabilities like toDashed, toHuman or toGetter and more.

Installation

Install this package using composer:

Methods

The inflector can be found at .

toSingular()

Returns the singular form of a word

toPlural()

Returns the plural form of a word

toSlug()

Converts a "Given string" to "given-string" or "another.String-you wouldWant" to "another-string-you-wouldwant". But in addition to that, it will convert "Annahäuser_Römertopf.jpg" into "annahaeuser-roemertopf-jpg"

NOTE: The implementation is heavily inspired (cough mostly stolen cough) from cakephp's Inflector::slug method. Kudos to them!

toFile()

Similar to toSlug() but is able to detect file extensions, and a path segment which will both be ignored while converting the file into a sluggified version.

toArray()

Converts a "Given string" to ["given", "string"] or "another.String-you wouldWant" to ["another", "string", "you", "would", "want"].

A thought on intelligent splitting: The default splitter is rather dumb when it comes to edge cases like IP, URL, and so on, because it will split them like I, P and U, R, L but stuff like HandMeAMango on the other hand will be correctly splitted like: hand, me, a, mango. If you set the second parameter to true, those edge cases will be handled more intelligently. Problems might occur when stuff like "ThisIsFAQandMore" is given, because the camelCase is broken the result will be: "this is fa qand more".

toSpacedUpper() | toHuman()

Converts a "Given string" to "Given String" or "another.String-you wouldWant" to "Another String You Would Want".

toCamelCase()

Converts a "Given string" to "GivenString" or "another.String-you wouldWant" to "AnotherStringYouWouldWant".

toCamelBack()

Converts a "Given string" to "givenString" or "another.String-you wouldWant" to "anotherStringYouWouldWant".

toDashed()

Converts a "Given string" to "given-string" or "another.String-you wouldWant" to "another-string-you-would-want".

setInflectorAdapter()

Can be used to inject a custom inflector adapter if you don't want to use the symfony inflector

toUnderscore() | toDatabase()

Converts a "Given string" to "given_string" or "another.String-you wouldWant" to "another_string_you_would_want".

toGetter()

Converts a "Given string" to "getGivenString" or "another.String-you wouldWant" to "getAnotherStringYouWouldWant". It allows you to add a custom prefix other than "get" using the second parameter. It will also sanitize the incoming string so if "getMyProperty" is given as string you will still end up with "getMyProperty" instead of "getGetMyProperty" which would not make much sense. The sanitation will remove the following prefixes "is", "has", "get" and "set".

toSetter()

Converts a "Given string" to "setGivenString" or "another.String-you wouldWant" to "setAnotherStringYouWouldWant". Sanitizes the input string like toGetter() does and has the same options.

toProperty()

This is in general an alias of toCamelBack(); But it will also strip away has/get/is/set prefixes from the given value before the camel back version is generated.

toComparable()

This method will convert the given string by unifying it. Unify means, it makes it comparable with other strings, by removing all special characters, converting everything to lowercase, counting all words and the number of their occurrence (optional) and sorting them alphabetically. This also means, that the text will no longer make sense for humans, but is easy to use for search and comparison actions.

toUuid()

Converts any given string into a UUID like: 123e4567-e89b-12d3-a456-426655440000. This is useful if you want to create, unique id's but want to combine multiple strings with different word order.

Note that "ASDF QWER" will result in the same ID as "QWER ASDF", because the values will be sorted alphabetically before the id is created. This makes sorting via first name and last name a lot easier.

Changing the Inflector implementation

As stated above you can change the actual implementation of the inflector by providing a adapter class for the inflector you would like to use the most (pull requests welcome!).

Writing an adapter is easy, create a new class:

After writing your adapter simply register it like:

After that the toSingular() and toPlural() methods will be resolved using your own adapter implementation.

Running tests

Postcardware

You're free to use this package, but if it makes it to your production environment I highly appreciate you sending me a postcard from your hometown, mentioning which of our package(s) you are using.

You can find my address here.

Thank you :D


All versions of inflection with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
symfony/string Version ^v5.4.10|^6.2.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package neunerlei/inflection contains the following files

Loading the files please wait ....