Hi,

I'd like to make use of @orm:postPersist/postUpdate/postRemove
features to perform audit logging ("who" and "when" has done "what" to
a Doctrine-powered entity) into DB.
The audit code is located in a service, say \My\TestBundle\Service
\AuditService.php.

The problem I'm facing is how to inject (and whether to inject at
all?) the AuditService in entity classes. The only option I see for
now is quite ugly and I really hope to see if there are more graceful
solutions:

Add the following code into MyTestBundle class:

    private static $containerInstance = null;

    public function setContainer(\Symfony\Component\DependencyInjection
\ContainerInterface $container = null) {
        parent::setContainer($container);
        self::$containerInstance = $container;
    }

    public static function getContainer() {
        return self::$containerInstance;
    }

And later on, in the @orm:postPersist/.... methods of my entities
classes, make calls like MyTestBundle::getContainer()->get('my.audit')-
>audit($this);

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to