Repository navigation
v1.6.68
v1.6.68 — Resource transformers apply to every resource
Added
- Agnostic resource transformers. Any extension can decorate the serialized output of any API resource without modifying the resource or its model. Register a transformer against an HTTP resource class, an Eloquent model class, an interface, or
'*'(subclasses match), andFleetbaseResource::resolve()applies it to JSON responses, nested resources, collection items, webhook payloads and broadcast payloads. Transformers chain in ascendingpriorityand can be scoped bycontexts(http,webhook,broadcast) andonly(internal,public). (#285) Fleetbase\Contracts\ResourceTransformer,Fleetbase\Contracts\PreparesResourceTransformation(a once-per-collectionprepare()hook for batch loading, so transformers never add N+1 queries),Fleetbase\Support\ResourceTransformerContext, and theFleetbase\Http\Transformers\Transformerbase class.- Closure transformers via
ResourceTransformerRegistry::register(fn (...) => ..., ['target' => ...]). CoreServiceProvider::$transformers,registerTransformers()andregisterTransformersFrom(__DIR__ . '/../Http/Transformers')for declarative and directory-based registration from extensions, mirroring expansions.
Changed
FleetbaseResourceCollectionresolves items (instead of callingtoArray()), sharing oneprepare()pass per collection. A hand-built collection with a manually setpreserveKeysnow filters item arrays with the item's flag.ResourceLifecycleEventpayloads, chat participant broadcasts,Utils::serializeJsonResource()and the cached internal user payload serialize throughresolve(), so transformers reach them and conditionalMissingValues are no longer emitted as{}.Find::httpResourceForModel()caches internal and public resolutions separately, consulting the request only when a model has a dedicatedInternalresource.
Removed
- Legacy duck-typed transformers (
$targetproperty + staticoutput($model, $data)),ResourceTransformerRegistry::transform(Model, array),resolveByTarget(),fixClassName()and the static$transformersarray. TheUserresource no longer calls the registry directly.
Dependencies
fleetbase/laravel-mysql-spatial^1.0.3. The spatialMysqlConnectionno longer connects to MySQL when the connection object is built, so resolvingDB::connection()during boot (for exampleartisan package:discoverduringcomposer install) no longer requires a reachable database.
Upgrade Steps
- Extensions that registered a legacy transformer must implement
Fleetbase\Contracts\ResourceTransformer(or extendFleetbase\Http\Transformers\Transformer) and register it through$transformersorregisterTransformersFrom(). See the README section "Resource transformers". The only known legacy consumer, aws-marketplace, is deprecated and is not updated.
What's Changed
- feat(resources): agnostic resource transformer registry by @roncodes in #285
- release: v1.6.68 by @roncodes in #286
Full Changelog: v1.6.67...v1.6.68