PHP code example of umanit / doctrine-singleton-bundle
1. Go to this page and download the library: Download umanit/doctrine-singleton-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
umanit / doctrine-singleton-bundle example snippets
new Umanit\DoctrineSingletonBundle\UmanitDoctrineSingletonBundle(),
namespace App\Entity\Content;
use Doctrine\ORM\Mapping as ORM;
use Umanit\DoctrineSingletonBundle\Model\SingletonInterface;
#[ORM\Table(name="page")]
class Page implements SingletonInterface
{
}
namespace Umanit\TranslationBundle\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Umanit\DoctrineSingletonBundle\Event\FilterSingletonEvent;
use Umanit\TranslationBundle\Doctrine\Model\TranslatableInterface;
class SingletonSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [FilterSingletonEvent::SINGLETON_FILTER_EVENT => ['onFilterEvent']];
}
public function onFilterEvent(FilterSingletonEvent $event)
{
$entity = $event->getEntity();
$filters = $event->getFilters();
if ($entity instanceof TranslatableInterface) {
$filters['locale'] = $entity->getLocale();
}
$event->setFilters($filters);
}
}