fluoresce / doctrine-undeletable
Doctrine annotation to make entities undeletable.
Installs: 30 450
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.4
- doctrine/orm: ~2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- vimeo/psalm: ^3.11
README
This library provides an Undeletable
annotation for Doctrine entities.
When added to an entity class, this annotation causes Doctrine to throw an exception when attempting to delete an entity.
Installation
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require fluoresce/doctrine-undeletable
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Documentation
Configuration
Symfony
Register the Doctrine event subscriber as a service. In services.yml
this
would look as follows.
services: fluoresce.listener.undeletable: class: Fluoresce\DoctrineUndeletable\EventListener\UndeletableSubscriber arguments: ["@annotation_reader"] tags: - { name: doctrine.event_subscriber, connection: default }
Basic Usage
This example shows a Book
ORM entity which should never be deleted.
<?php use Doctrine\ORM\Mapping as ORM; use Fluoresce\DoctrineUndeletable\Mapping\Undeletable; /** * @ORM\Entity * @Undeletable */ class Book { … }
When you attempt to delete a Book
, an exception will be thrown.
$book = $entityManager->find('Book', 123); $entityManager->remove($book); try { $entityManager->flush(); } catch (Fluoresce\DoctrineUndeletable\Exception\UndeletableObjectException $e) { // $book was not deleted from the database }