dmstr / api-platform-utils-bundle
Generic utilities for API Platform projects: UUID resolver, credential encryption, OpenAPI enhancements, Hydra operations, IriReferenceArray autocomplete, DB-JSON CLI tools, JWT security decorator.
Package info
github.com/dmstr/api-platform-utils-bundle
Type:symfony-bundle
pkg:composer/dmstr/api-platform-utils-bundle
Requires
- php: >=8.4
- ext-sodium: *
- api-platform/core: ^3.0|^4.0
- doctrine/orm: ^2.0|^3.0
- psr/log: ^3.0
- symfony/config: ^7.0
- symfony/dependency-injection: ^7.0
- symfony/event-dispatcher: ^7.0
- symfony/framework-bundle: ^7.0
- symfony/http-kernel: ^7.0
- symfony/uid: ^7.0
Requires (Dev)
- phpunit/phpunit: ^12.0
This package is auto-updated.
Last update: 2026-07-22 16:14:54 UTC
README
dmstr/api-platform-utils-bundle
Generic helpers for API Platform projects.
Features (planned)
- Partial-UUID lookups (
UuidResolver,UuidSearchFilter) - JWT security decorator for the OpenAPI doc
- Credential encryption service (
CredentialEncryption) #[IriReferenceArray]attribute + Doctrine listener + persist processor + OpenAPI schema factory for autocomplete-rendered IRI collections- DB-JSON CLI tools (
db:export-json,db:import-json) AbstractJsonSchemaInputCommandbase class for JSON-Schema-validated CLI
Hydra operations (hydra:operation)
AddHydraOperationsSubscriber enriches JSON-LD runtime responses with a hydra:operation array so clients can discover the available operations without parsing the static docs:
- Item GET responses list the item-level operations (
GET,PUT,PATCH,DELETE, custom/resource/{id}/<verb>actions) with the{id}placeholder resolved to the actual identifier. - Collection GET responses (
hydra:Collection) list the collection-level operations (GET, createPOST, custom/resource/<verb>actions).
Security filtering (HATEOAS)
By default each operation is checked against the current security token via API Platform's ResourceAccessChecker (api_platform.security.resource_access_checker); operations whose security expression does not grant access are omitted. The server therefore only advertises what the current user may actually execute — a UI can derive canCreate/canUpdate/canDelete directly from the runtime hydra:operation instead of the role-independent static docs.
Rules:
- Operations without a
securityexpression stay visible (default: allowed). - Item operations are evaluated with the loaded entity as
object(when resolvable from the request); collection operations are evaluated withobject = null. - Only collection-level operations are checked on collection responses — one check per operation, never per
hydra:member. - Expression evaluation errors fail closed (the operation is hidden).
- Without
symfony/security-bundlethe checker service is absent and filtering is skipped.
Configuration:
dmstr_api_platform_utils: hydra_operations: enabled: true api_prefix: '/api' event_priority: -10 # set to false to restore the unfiltered (pre-0.4) behavior filter_operations_by_security: true
HTTP caching
With filtering active, item and collection responses become user-dependent: the subscriber emits Vary: Authorization so shared HTTP caches never serve one user's operation set to another. The static /api/docs.jsonld stays role-independent and cacheable. If your stack caches API responses in a reverse proxy, verify it honors Vary — otherwise exclude these responses from caching.
License
MIT © diemeisterei GmbH