tenolo/doctrine-walker-bundle

This bundle add a event driven SQL output walker.

dev-master / 1.0.x-dev 2019-07-22 08:37 UTC

This package is auto-updated.

Last update: 2024-12-22 19:48:40 UTC


README

tenolo

PHP Version Latest Stable Version Latest Unstable Version Total Downloads Total Downloads License

Doctrine Walker Bundle

A Symfony Bundle to add a event driven sql walker in Doctrine.

Install instructions

First you need to add tenolo/doctrine-walker-bundle to composer.json:

{
   "require": {
        "tenolo/doctrine-walker-bundle": "~1.0"
    }
}

or just do composer require tenolo/doctrine-walker-bundle

Please note that dev-master latest development version. Of course you can also use an explicit version number, e.g., 1.0.*.

How to use

Just register some events.

<?php

namespace Some\Namespace;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Tenolo\Bundle\DoctrineWalkerBundle\Event\SqlWalkerEvent;

/**
 * Class ExampleWalkerListener
 */
class ExampleWalkerListener implements EventSubscriberInterface
{

    /**
     * @inheritDoc
     */
    public static function getSubscribedEvents()
    {
        return [
            SqlWalkerEvent::FROM_CLAUSE => 'walkFromClause',
        ];
    }

    /**
     * @param SqlWalkerEvent $event
     */
    public function walkFromClause(SqlWalkerEvent $event): void
    {
        $sql = $event->getSql();
        $em = $event->getEntityManager();
        $conn = $event->getConnection();
        $query = $event->getQuery();

        // manipulate sql
        $sql = 'NONSENSE';

        $event->setSql($sql);
    }

}