eufony/inflector

Common interfaces for inflection libraries.

v2.1.1 2023-02-08 07:54 UTC

This package is auto-updated.

Last update: 2024-04-08 10:14:12 UTC


README

Packagist Downloads GitHub Stars Issues
License Community Built

eufony/inflector provides a standardized interface for linguistic inflection libraries.

eufony/inflector is a PHP library that aims to improve interoperability between linguistic inflection implementations. It provides a common interface for changing the capitalization of strings, as well as the pluralization and singularization of words.

Interested? Here's how to get started.

Getting started

Installation

eufony/inflector is released as a Packagist package and can be easily installed via Composer with:

composer require "eufony/inflector"

Basic Usage

eufony/inflector provides InflectorInterface, which defines the following methods:

// Convert between `PascalCase`, `snake_case`, and `camelCase`.
echo $inflector->toPascalCase($string);
echo $inflector->toSnakeCase($string);
echo $inflector->toCamelCase($string);

// Convert between pluralized and singularized words.
echo $inflector->pluralize($string);
echo $inflector->singularize($string);

It also provides a couple of pseudo-implementations to get you started:

// A fake implementation based on the Null Object Pattern
// that returns any string it is given without any modifications.
$inflector = new NullInflector();

// A wrapper class to manually define exceptions to the return values of another implementation.
$inflector = new ExceptionAdapter($inflector, cases: [["id", "id", "ID"]], words: ["moose", "meese"]);

// A wrapper class around the inflector implementation by the Doctrine project.
$inflector = new DoctrineInflector();

Contributing

Found a bug or a missing feature? You can report it over at the issue tracker.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see https://www.gnu.org/licenses/.