Events

The PWA Bundle uses Symfony's 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:

Event API Reference

PreManifestCompileEvent

Properties:

Property
Type
Access
Description

manifest

Manifest

read/write

The manifest DTO object to modify

locale

?string

readonly

The locale for this compilation (null for default)

Usage:

PostManifestCompileEvent

Properties:

Property
Type
Access
Description

manifest

Manifest

read/write

The manifest DTO object

data

string

read/write

The compiled manifest as a JSON string

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

Last updated

Was this helpful?