1.2 KiB
1.2 KiB
PCM Metadata Bundle
Easily add scalar metadata to a Symfony entity via the use of a key-value interface.
Installation
- Add this repository to
composer.json:
"repositories": [
{
"type": "vcs",
"url": "ssh://git@git.pcmdev.co.uk:2222/pcm-libraries/pcm-metadata-bundle.git"
}
],
- Install the bundle:
composer require pcm/metadata-bundle
- If not set already add the following config to
doctrine.yamlto prevent errors:
doctrine:
orm:
enable_native_lazy_objects: true
Usage
- Use the
MetadataTraitinside an entity:
class MyEntity
{
use MetadataTrait;
}
- Create and execute a new migration. The trait adds a
metadatadatabase field and as such we need to create a migration. - Access the metadata object with the readonly property
metadata:
$entity->metadata->set("name", "PCM");
$entity->metadata->get("name"); // "PCM"
$entity->metadata->isSet("name"); // true
Like updating the value of a property normally, setting metadata values will not automatically update the database. You must call
flush()from theEntityManageras usual when you wish to persist data.