Skip to main content
Version: v2.0 (upcoming)

Utilities

config/packages/utility.php wires the parameter resolver and parameter converter pipelines used throughout the framework, along with the Doctrine Inflector.

What it does

  • Registers default ParameterResolverInterface implementations in a chained resolver.
  • Registers default ParameterConverterInterface implementations in a chained converter.
  • Binds ParameterConverterInterface to ChainedParameterConverter.
  • Binds ParameterResolverInterface to ChainedParameterResolver.
  • Creates a Doctrine Inflector using the default English factory.

Parameter resolvers

Resolvers determine how method/function parameters are populated when the framework invokes a controller, listener, or command.

ResolverDescription
IndexedParameterResolverResolves parameters by their positional index from a provided argument list.
ContainerParameterResolverResolves parameters by type-hinting them against the DI container.

Resolvers are tried in order. Add custom resolvers in services.php:

// services.php
use function DI\add;
use function DI\get;

'utility.parameter_resolvers' => add([
get(\Application\Utility\RequestAttributeResolver::class),
get(\ForestCityLabs\Framework\Utility\ParameterResolver\IndexedParameterResolver::class),
get(\ForestCityLabs\Framework\Utility\ParameterResolver\ContainerParameterResolver::class),
]),

Parameter converters

Converters transform raw scalar values (e.g. route path segments, request body fields) into typed PHP objects before they are passed to a resolver.

ConverterDescription
UuidParameterConverterConverts UUID strings into Ramsey\Uuid\UuidInterface instances.
DateTimeParameterConverterConverts date/time strings into DateTimeInterface instances.
InputTypeConverterConverts associative arrays into GraphQL input type objects.

Add custom converters in services.php:

// services.php
use function DI\add;
use function DI\get;

'utility.parameter_converters' => add([
get(\Application\Utility\MoneyParameterConverter::class),
]),

Inflector

The Doctrine\Inflector\Inflector service is available for autowiring wherever string inflection (pluralisation, singularisation, camelCase ↔ snake_case) is needed.

Dependencies

PackageDescription
doctrine/inflectorString inflection utility.