phrity/util-transformer
Type transformers, normalizers, and resolvers for PHP. Convert values between types, encode and decode JSON, flatten nested arrays, and stack transformers with recursion and first-match resolvers for flexible data transformation.
Architecture fit: phrity/util-transformer is a generic PHP utility library, not a Laravel package. Its canTransform()/transform() contract, composable resolvers, and optional target-type argument map cleanly to Laravel service-container bindings and pipeline-style application code. It fits where Laravel apps frequently hand-roll normalization: API resource serialization, request payload normalization, JSON decoding, flattening nested arrays for storage, and converting domain objects (DateTime, enums, Stringable, Throwable) into transport-safe values. The SymfonyNormalizerWrapper is useful for teams already using Symfony Serializer components.
Integration feasibility: Composer install is straightforward and does not require Laravel auto-discovery. A TPM should expect to write adapter code: a service provider binding a configured resolver, custom transformers for Laravel-specific types such as Carbon or Eloquent models, and conventions for when to call canTransform() before transform(). The package does not provide Eloquent casts, validation rules, Blade helpers, or Laravel-native facades. Integration is feasible but requires deliberate glue ownership.
Technical risk: The package has 0 stars, 0 dependents, and a single-maintainer profile, so ecosystem validation is very low. The low overall score and recent/future-dated releases suggest limited production evidence. The main technical risks are silent type coercion, recursion depth and performance on deeply nested payloads, breaking changes in a pre-2.0 library, and lack of Laravel-specific documentation. PHP 8.1+ is required. MIT licensing is acceptable. Static analysis and contract tests are important because dynamic PHP type conversion can fail at runtime rather than compile time.
Key questions: Which Laravel use cases justify the dependency versus native json_encode, Laravel casts, or Symfony Serializer? What is the measured overhead of canTransform() checks and recursive resolvers in high-traffic endpoints? Who owns custom transformers and version upgrades? What is the fallback if the maintainer stops releasing? How will transformer behavior be tested across nulls, enums, dates, nested arrays, and exception objects? Are there security concerns when transforming untrusted request payloads?
Stack fit: Target PHP 8.1+ and supported Laravel versions. Register a configured transformer as a singleton in a service provider. Use FirstMatchResolver and RecursionResolver for API resource output and request normalization. Use JsonDecoder and FlattenDecoder for JSON columns or flattened storage. Avoid introducing the package into queue workers or async pipelines unless payload sizes are bounded and benchmarked.
Migration path: Start with a bounded pilot, such as one API resource or one form request path. Replace hand-written normalization only where behavior is well covered by tests. Then expand to request middleware and JSON-column handling. Centralize resolver configuration in a service provider once the pilot proves stable. Keep legacy serialization paths behind feature flags until parity is demonstrated.
Compatibility: Confirm Composer constraints against the Laravel version, PHP version, and existing Symfony components. Pin the package to an exact minor or patch version. Run PHPStan or Psalm against transformer chains. Test custom transformers for Carbon, Eloquent models, and application DTOs before broad rollout. The package has no Laravel version constraints, so Laravel compatibility must be validated internally.
Sequencing: 1) Run a short technical spike with representative payloads. 2) Define internal transformer interfaces and service-provider bindings. 3) Pilot in a low-risk API resource. 4) Add request normalization and JSON/flatten decoding. 5) Document custom transformers and failure behavior. 6) Review performance, error rates, and maintenance burden before expanding.
Maintenance: Internal ownership is required. The package is small and MIT-licensed, but low adoption means the team must track releases, test upgrades, and potentially fork or vendor critical transformers. Budget time for dependency review each Laravel/PHP upgrade cycle.
Support: Community support is minimal. There is no commercial SLA, no large dependent ecosystem, and limited evidence of production use. The team should maintain internal documentation, examples, and a decision record for why the dependency exists.
Scaling: Recursive resolution and repeated canTransform() checks can become expensive on large or deeply nested payloads. Benchmark against realistic API responses and database row counts. Cache configured resolvers, avoid unbounded recursion, and chunk large collections before transformation.
Failure modes: Watch for silent type coercion, unexpected null or boolean conversion, recursion exhaustion, incompatibility with custom Laravel types, and performance degradation in hot paths. Add validation before transformation, monitor error rates after rollout, and keep rollback paths for serialization changes.
Ramp-up: The API is simple enough for Laravel developers to learn quickly, but the integration patterns are not Laravel-native. Provide internal examples for service-provider binding, custom transformers, and testing. A short spike plus paired review is enough to onboard most teams, but the low ecosystem maturity means adoption should be deliberate rather than default.
How can I help you explore Laravel packages today?