Oihana PHP Commands

InflectorTrait

Provides functionality to initialize and store a Symfony String Inflector.

The inflector is used to convert words between singular and plural forms. This trait offers a flexible initialization mechanism allowing:

  • Direct assignment of an InflectorInterface instance
  • Resolution from a PSR-11 container via a service ID
  • Automatic fallback to EnglishInflector if none is provided

Intended for classes that need consistent singular/plural transformations with support for dependency injection and configuration.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

INFLECTOR  = 'inflector'
The 'inflector' parameter.

Properties

$inflector  : InflectorInterface
The string inflector reference.

Methods

initializeInflector()  : static
Initializes the string inflector to be used by this instance.

Constants

INFLECTOR

The 'inflector' parameter.

public mixed INFLECTOR = 'inflector'

Properties

$inflector

The string inflector reference.

public InflectorInterface $inflector

Methods

initializeInflector()

Initializes the string inflector to be used by this instance.

protected initializeInflector([array<string, mixed> $init = [] ][, ContainerInterface|null $container = null ][, InflectorInterface|null $defaultInflector = null ]) : static

This method determines which InflectorInterface implementation should be applied:

  • If $init[static::INFLECTOR] is a non-empty string corresponding to a service name available in the DI container, that service will be fetched and used as the inflector.
  • If $init[static::INFLECTOR] is already an InflectorInterface instance, it is used directly.
  • Otherwise, the provided $defaultInflector is used; if not given, a new EnglishInflector is created.
Parameters
$init : array<string, mixed> = []

Optional initialization parameters. May contain the key static::INFLECTOR with:

  • A service ID (string) resolvable via $container
  • Or an InflectorInterface instance.
$container : ContainerInterface|null = null

Optional PSR-11 container for resolving a service name into an InflectorInterface.

$defaultInflector : InflectorInterface|null = null

Fallback inflector to use if no specific instance is found or provided.

Tags
throws
ContainerExceptionInterface

If the container encounters an error while retrieving the inflector service.

throws
NotFoundExceptionInterface

If the requested inflector service is not found in the container.

Return values
static

Returns the current instance for method chaining.


        
On this page

Search results