Events

The PWA Bundle uses Symfony's PSR-14 Event Dispatcher system to allow customization of the manifest generation process. You can listen to these events to modify the manifest before or after compilation.

Available Events

The bundle dispatches two main events during manifest generation:

PreManifestCompileEvent

Dispatched before the manifest is compiled. Use this event to:

  • Add dynamic data to the manifest

  • Modify manifest properties based on runtime conditions

  • Inject user-specific or request-specific information

PostManifestCompileEvent

Dispatched after the manifest is compiled. Use this event to:

  • Validate the compiled manifest

  • Add additional processing

  • Log manifest details

  • Perform cleanup operations

Basic Event Listener

Here's how to create an event listener for both events:

circle-info

Event listeners are automatically registered when using the #[AsEventListener] attribute. No additional configuration needed!

Use Cases

Adding Dynamic Data

Inject dynamic information like user preferences or runtime configuration:

Multi-Locale Support

Adapt the manifest for different locales:

Environment-Based Configuration

Modify manifest based on the environment (dev/staging/prod):

Logging and Validation

Validate manifest data and log issues:

Adding Analytics Tracking

Include analytics parameters in URLs:

Event API Reference

PreManifestCompileEvent

Methods:

  • getManifest(): Returns the Manifest DTO object (read/write)

  • getRequest(): Returns the current Request object (read-only)

Usage:

PostManifestCompileEvent

Methods:

  • getData(): Returns the compiled manifest as an array (read-only)

  • getRequest(): Returns the current Request object (read-only)

Usage:

Best Practices

  1. Use PreCompile for modifications: Modify the manifest object in PreManifestCompileEvent

  2. Use PostCompile for validation: Check the compiled data in PostManifestCompileEvent

  3. Keep listeners focused: Each listener should handle one specific concern

  4. Avoid heavy operations: Events are dispatched on every manifest request

  5. Test thoroughly: Ensure your modifications don't break manifest validity

  6. Handle errors gracefully: Don't throw exceptions that could break manifest generation

Debugging Events

Enable logging to see when events are dispatched:

Then log in your listener:

Last updated

Was this helpful?