https://github.com/phpnomad/mutator
Mutation strategy interfaces for transforming data through composable adapters
https://github.com/phpnomad/mutator
framework mutator php phpnomad platform-agnostic transformation
Last synced: 17 days ago
JSON representation
Mutation strategy interfaces for transforming data through composable adapters
- Host: GitHub
- URL: https://github.com/phpnomad/mutator
- Owner: phpnomad
- License: mit
- Created: 2023-11-03T00:53:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2026-04-10T02:10:21.000Z (about 2 months ago)
- Last Synced: 2026-04-10T02:36:10.018Z (about 2 months ago)
- Topics: framework, mutator, php, phpnomad, platform-agnostic, transformation
- Language: PHP
- Homepage: https://phpnomad.com
- Size: 80.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# phpnomad/mutator
[](https://packagist.org/packages/phpnomad/mutator)
[](https://packagist.org/packages/phpnomad/mutator)
[](https://packagist.org/packages/phpnomad/mutator)
[](https://packagist.org/packages/phpnomad/mutator)
`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
```bash
composer require phpnomad/mutator
```
## Overview
The package exports five interfaces and one trait:
- `Mutator` is the stateful transformation contract. An implementation holds input in its own state and exposes a single `mutate(): void` call that produces a result internally.
- `MutatorHandler` is the functional counterpart. Its `mutate(...$args)` takes arguments and returns a result directly, with no instance state to manage.
- `MutationAdapter` handles bidirectional conversion between raw data and `Mutator` instances, keeping data marshaling separate from transformation logic.
- `MutationStrategy` attaches handler factories to named actions, enabling dynamic dispatch and deferred instantiation through a `callable():MutatorHandler` getter.
- `HasMutations` lets an object advertise the mutations it supports via `getMutations(): array`, which is useful when you want capabilities to be discoverable at runtime.
- `CanMutateFromAdapter` is a trait that runs the full convert, mutate, convert workflow in a single `mutate(...$args)` call on any class that holds a `MutationAdapter` property.
## Documentation
Full package documentation, including individual interface references and the adapter workflow walkthrough, lives at [phpnomad.com](https://phpnomad.com).
## License
MIT. See [LICENSE.txt](LICENSE.txt).