php-standard-library/dict
Utility functions for working with PHP associative arrays (“dicts”): create, map, filter, and transform collections while preserving keys. Lightweight helpers from PHP Standard Library for cleaner, safer array manipulation.
config() arrays) and Eloquent attribute handling, reducing cognitive load for teams familiar with the ecosystem.dict->set('key', $value)) over implicit array access, lowering ambiguity and runtime errors (e.g., UndefinedIndex).Collection is overkill (e.g., config bags, dynamic metadata) while avoiding the complexity of Symfony’s OptionsResolver.Dict<string, mixed>) for stricter validation, though generics are limited.merge()), updating (update()), and filtering (filter()) reduce boilerplate for common transformations.Arrayable, Jsonable, or Macroable interfaces, requiring custom implementations.pluck(), groupBy()), necessitating fallback to Laravel’s Collection for complex operations.app(Dict::class)).config() arrays for feature flags, app settings, or environment overrides.user->metadata->dict()).Dict::fromArray($request->all())).Illuminate\Support\Collection via adapters).Dict facade or Arrayable support) necessitates custom boilerplate.Arrayable or introduces stricter typing.Dict<int, string>).toArray() or serialization (mitigate with depth limits).Jsonable or API responses (require custom implementations).Dict provide the highest ROI? (e.g., config management, request payloads, or Eloquent attributes?)Dict?Dict facade or service provider for consistency?Jsonable interface)?Dict vs. raw arrays for critical paths (e.g., request validation, config loading)?Dict over arrays?config('app.*') with Dict instances (e.g., new Dict(config('app'))) for type-safe access and merging.Dict::fromArray($request->all())) to enforce structure and defaults.Dict trait for dynamic attributes (e.g., user->metadata->dict()) or use mixins to wrap attributes array.Arrayable/Jsonable interfaces to convert Dict to arrays/JSON seamlessly.Dict as a singleton or per-request dependency for global key-value stores (e.g., feature flags).Illuminate\Support\Collection via adapters (e.g., Dict::fromCollection($collection)).Illuminate\Http\Request or Illuminate\Database\Eloquent\Model to return Dict instances.Dict with tagged dependencies (e.g., app()->tag(['config', 'Dict'])).Dict in unit tests using Laravel’s Mockery or PHPUnit.// Before: config('app.theme') ?? 'light'
// After: (new Dict(config('app')))->get('theme', 'light')
Dict for all dependencies.Dict facade for global access (e.g., Dict::config()).Illuminate\Database\Eloquent\Model with a Dict trait for attributes.Arrayable/Jsonable for Dict to support API responses.Dict conversions.Dict as a singleton or per-request (e.g., app()->singleton(Dict::class, fn() => new Dict(config('app')))).attributes or relations as Dict instances.Dict::fromArray()/toArray().Dict with Laravel-style macros (e.g., Dict::macro('mergeRecursive', ...)).ArrayAccess and IteratorAggregate interfaces.Collection or ArrayCollection via adapters.Mockery.Dict is used in service container bindings.Jsonable (resolve via custom toJson()).| **Priority
How can I help you explore Laravel packages today?