Download the PHP package somnambulist/read-models-bundle without Composer
On this page you can find all versions of the php package somnambulist/read-models-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download somnambulist/read-models-bundle
More information about somnambulist/read-models-bundle
Files in somnambulist/read-models-bundle
Package read-models-bundle
Short Description Symfony integration for somnambulist/read-models
License MIT
Informations about the package read-models-bundle
Read-Models Bundle for Symfony
Integrates read-models into Symfony via a bundle.
Installation
Install using composer, or checkout / pull the files from github.com.
- composer require somnambulist/read-models-bundle
- add the bundle class to
config/bundles.phpas the last bundle- Note: if not configured last, then any custom doctrine types may not be assigned to the type caster as the Manager will boot too soon.
- add a config file (
config/packages/somnambulist.yaml) with the configuration - map any custom casters via the
services.yamland tags - make some models
- load some data:
<model>::find()
An example config in config/packages/somnambulist.yaml could be:
There are 2 event subscribers that are auto-registered:
- identity map clear on kernel request, terminate
- messenger clear on message handled / failed
If messenger is not installed, the listener will be disabled automatically.
Connections
Each model type can have a custom connection by using the fully qualified class name as the
key. When referencing the Doctrine connections, be sure to leave off the @ prefix if copying
from elsewhere.
Note that if the default is not specified, then the currently configured Doctrine default will be auto-registered.
Adding Attribute Casters
Add attribute casters as services and tag them with: somnambulist.read_models.type_caster to have
them automatically registered with the Managers attribute caster instance.
To use the attribute-model generic type casters, and them as services and configure as needed:
Or if you don't need configuration, or have your own; use a resource:
The attribute names should be the array key names that the values are expected to appear in from
the data source. For example: if a Product model accesses a products table that has unit_value
and unit_cur fields, this could be converted to a Money object by using the MoneyCaster:
Then the caster can be referenced in the casts as: 'price' => 'product_price' and the unit_value
and unit_cur attributes will be removed in favour of the single "price" attribute that will be a
Money value object. If the originals should be left in place, set $remove to false.
Additional casters can be added at any time; and existing casters may be overridden by re-using an existing type name however this is discouraged. Note that once a type is registered it cannot be removed.
Usage
See read-models for detailed docs on usage and attribute-models for more on the attribute caster.
All versions of read-models-bundle with dependencies
somnambulist/read-models Version ^4.1
symfony/framework-bundle Version ^6.4|^7.0