phpnomad / mutator
1.0.0
2024-12-18 17:18 UTC
Requires (Dev)
- phpnomad/tests: ^0.1.0
This package is auto-updated.
Last update: 2026-04-14 23:08:15 UTC
README
phpnomad/mutator provides interfaces and a trait for structured data transformation. Instead of scattering one-off transformation helpers across your codebase, you define mutators that follow a consistent contract and route input through them via adapters. The package has no runtime dependencies and is used by other PHPNomad packages, including phpnomad/loader, to handle transformation steps in a testable, composable way.
Installation
composer require phpnomad/mutator
Overview
The package exports five interfaces and one trait:
Mutatoris the stateful transformation contract. An implementation holds input in its own state and exposes a singlemutate(): voidcall that produces a result internally.MutatorHandleris the functional counterpart. Itsmutate(...$args)takes arguments and returns a result directly, with no instance state to manage.MutationAdapterhandles bidirectional conversion between raw data andMutatorinstances, keeping data marshaling separate from transformation logic.MutationStrategyattaches handler factories to named actions, enabling dynamic dispatch and deferred instantiation through acallable():MutatorHandlergetter.HasMutationslets an object advertise the mutations it supports viagetMutations(): array, which is useful when you want capabilities to be discoverable at runtime.CanMutateFromAdapteris a trait that runs the full convert, mutate, convert workflow in a singlemutate(...$args)call on any class that holds aMutationAdapterproperty.
Documentation
Full package documentation, including individual interface references and the adapter workflow walkthrough, lives at phpnomad.com.
License
MIT. See LICENSE.txt.