diff --git a/src/Bridge/Nette/SluggableExtension.php b/src/Bridge/Nette/SluggableExtension.php new file mode 100644 index 0000000..395342a --- /dev/null +++ b/src/Bridge/Nette/SluggableExtension.php @@ -0,0 +1,58 @@ +registerSubscriberIntoEntityManager = $registerSubscriberIntoEntityManager; + } + + /** + * {@inheritdoc} + */ + public function loadConfiguration(): void + { + $builder = $this->getContainerBuilder(); + + $builder->addDefinition($this->prefix('storage')) + ->setType(SixtyEightPublishers\DoctrineSluggable\SluggableDefinitionStorage::class); + + $builder->addDefinition($this->prefix('event_subscriber')) + ->setType(SixtyEightPublishers\DoctrineSluggable\SluggableEventSubscriber::class); + + $builder->addDefinition($this->prefix('helper')) + ->setType(SixtyEightPublishers\DoctrineSluggable\Helper\UniqueSlugHelper::class); + } + + /** + * {@inheritdoc} + */ + public function beforeCompile(): void + { + if (FALSE === $this->registerSubscriberIntoEntityManager) { + return; + } + + $builder = $this->getContainerBuilder(); + + $builder->getDefinition($builder->getByType(Doctrine\ORM\EntityManagerInterface::class)) + ->addSetup('?->getEventManager()->addEventSubscriber(?)', [ + '@self', + $builder->getDefinition($this->prefix('event_subscriber')), + ]); + } +}