yansongda/supports
Supports is a small PHP utility library from the yansongda ecosystem that simplifies working with arrays, configuration, and pipelines. It provides handy helpers for array access and manipulation, config handling, and pipeline processing, making it useful for Laravel or PHP projects that need lightw...
Illuminate\Pipeline remains marginal unless the package is already in the dependency graph.Yansongda\Supports\Json): Adds a thin, exception-first wrapper over native json_encode()/json_decode(). Architecturally this is a convenience layer, not a new capability — Laravel and PHP 8.2 already offer JSON_THROW_ON_ERROR and Illuminate\Support\Js. Treat it as standardization glue (one encoding policy across services) rather than a reason to adopt.Json::encode()/decode() can be adopted file-by-file with no container, config, or bootstrapping changes. Lowest-risk entry point in the package.HasHttpRequest still needs explicit mixin/container wiring; unchanged effort.Json::encode() defaults to JSON_UNESCAPED_UNICODE (native default is 0) and Json::decode() defaults to associative arrays. Behavior differs from native calls unless flags are passed explicitly — a subtle consistency trap across a codebase.Json::decode('{bad') now throws \JsonException where native returns null. Uncaught in controllers/jobs, this converts previously silent bad-input handling into 500s. Requires an explicit error-handling convention.json_encode($v, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE) delivers identical behavior with zero dependency. The marginal utility is convention enforcement, not capability.HasHttpRequest in large codebases.Json replace all ad-hoc json_encode/json_decode calls, or just new code? A partial rollout creates two encoding conventions.Json::encode()'s JSON_UNESCAPED_UNICODE default, and does any downstream consumer (logs, API signatures, cache keys, hashing) depend on escaped output?JSON_THROW_ON_ERROR + a one-line internal helper sufficient, avoiding the dependency entirely?spatie/array / Laravel Arr still cover the array/config utilities better?json_encode/json_decode call sites (including false-return and json_last_error() checks) to size the Json adoption surface.Log.^4.1 in composer.json on a single pilot service; run the full test suite.Json in One Service
Json::encode()/decode() in a bounded module first.$flags where native parity is required; never rely on the default silently.\JsonException maps to a 422/bad-request rather than a 500.json_encode), or deliberately stop at the pilot and drop the dependency.HasHttpRequest via Service Provider mixin or container binding; alias methods to avoid collisions.Illuminate\Pipeline.| Feature | Compatibility | Workaround |
|---|---|---|
| PHP >= 8.2 | ✅ Laravel 11/12 | Blocks Laravel ≤10 on PHP < 8.2 — defer those services |
| Guzzle 7.x | ✅ Laravel 9+ baseline | Wrapper facade if a service pins Guzzle 6 |
Json utility |
✅ Drop-in, no wiring | Pass explicit flags for native parity |
Json::decode() exceptions |
⚠️ Changes failure semantics | Global handler mapping / try-catch convention |
JSON_UNESCAPED_UNICODE default |
⚠️ Differs from native | Pass 0 where escaped output is expected |
| Array/Config utilities | ✅ Works alongside Arr |
Use selectively; compare with spatie/array |
HasHttpRequest trait |
⚠️ Not Laravel-native | Container binding + method aliases |
| Pipeline support | ✅ Compatible | Only adopt if it beats Illuminate\Pipeline |
| Removed logger (v3.0.0) | ❌ Breaking for legacy code | \Log:: facade |
| Undocumented v4.0.0 changes | ⚠️ Unknown | Full changelog diff required before upgrade |
Json adoption + exception convention in that service only.JSON_THROW_ON_ERROR.Json convention and the exception policy.Json is a thin wrapper over native functions; traits compile away. No measurable throughput or memory impact.HasHttpRequest across many classes increases collision surface; prefer a small number of explicitly-composed service classes.\JsonException → HTTP 500s / failed jobs where previously null or false was tolerated. Highest-probability new failure. Mitigation: global handler mapping + mandatory tests for malformed payloads.JSON_UNESCAPED_UNICODE default (e.g., differing cache keys, request signatures, log parsers, snapshot tests). Mitigation: lint rule enforcing explicit flags.Json::decode() breaks consumers expecting stdClass (e.g., property access). Mitigation: pass $assoc = false explicitly at those call sites.Json is learnable in minutes.Json adoption, with an explicit go/no-go on whether the wrapper justifies the dependency over native JSON_THROW_ON_ERROR.How can I help you explore Laravel packages today?