Coder Social home page Coder Social logo

How to define a storage mapper? about auditor HOT 4 CLOSED

bertoost avatar bertoost commented on September 20, 2024
How to define a storage mapper?

from auditor.

Comments (4)

DamienHarper avatar DamienHarper commented on September 20, 2024

Hi @bertoost, auditor can be used outside of a Symfony project, that's why it doesn't require an autowired Symfony service for storage mapper.

A storage mapper has to be a closure/callable/invokable. It takes 2 parameters: an entity name and an array of storage services. It must return the storage service (from the provided array) handling the provided entity name.

There was a bug until version 2.4.2 which prevented using invokable classes, it's fixed now.

Let me give you an example:

<?php
namespace App;

use App\Entity\MyEntity1; 
use App\Entity\MyEntity2; 
use App\Entity\MyEntity3; 
use DH\Auditor\Provider\Service\StorageServiceInterface;

/**
 * MyStorageMapper is an invokable class/service
 *
 */
class MyStorageMapper
{
    // the service expects 2 parameters and should return an object 
    // implementing StorageServiceInterface
    public function __invoke(string $entity, array $storageServices): StorageServiceInterface {
        return \in_array($entity, [MyEntity1::class, MyEntity2::class], true) ? $storageServices['db1'] : $storageServices['db2'];
    }
}

Then, if using auditor-bundle, register it as a storage mapper

# config/packages/dh_auditor.yaml
dh_auditor:
    providers:
        doctrine:
            # Invokable service that maps audit events to storage services
            storage_mapper: App\MyStorageMapper

from auditor.

bertoost avatar bertoost commented on September 20, 2024

Thanks @DamienHarper ! The storage mapper now works.
I had to report this on the bundle maybe ;-)

Therefore I am now running into this error when running schema-update command of doctrine.

In MappingException.php line 26:

  [Doctrine\Persistence\Mapping\MappingException]
  The class 'App\Entity\Tenant\Student' was not found in the chain configured namespaces App\Entity\Main

The namespace is configured on the second entity-manager which I do correctly map in the storage mapper.

from auditor.

dmitryuk avatar dmitryuk commented on September 20, 2024

@bertoost can you provide more debug trace?

from auditor.

DamienHarper avatar DamienHarper commented on September 20, 2024

@bertoost I close this issue since no feedback has been provided, feel free to reopen it if needed.

from auditor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.