Doctrine Behaviors

โ† Doctrine Behaviors

Ashterix

docs: Doctrine section with Doctrine Behaviors and Doctrine Helper (uk + en)

en/docs/doctrine/doctrine-behaviors/README.md new file +60 โˆ’0

1 + # Doctrine Behaviors
2 +
3 + :::block class="package-card"
4 + <include>(docs/doctrine/doctrine-behaviors/.info.md)
5 + :::
6 +
7 + A set of behaviors for Doctrine ORM entities in Symfony 7 / 8: timestamps, change authors, soft delete, translations, slugs, trees, UUIDs and a change log. A behavior is enabled with an interface and a trait on the entity โ€” the bundle adds the required columns to the mapping and fills them in Doctrine events.
8 +
9 + :::info
10 + The package is a fork of [KnpLabs/DoctrineBehaviors](https://github.com/KnpLabs/DoctrineBehaviors) (via the intermediate fork [Miets/DoctrineBehaviors](https://github.com/Miets/DoctrineBehaviors)). The original does not work with Symfony newer than 6.3 or with DBAL 4; the UFO-Tech fork updates the code for Symfony 7+ / 8, Doctrine ORM 3 and DBAL 4. The ideas, the API and most of the code come from the KnpLabs authors, MIT license.
11 + :::
12 +
13 + This documentation describes version 2.0.0.
14 +
15 + ## What it looks like
16 +
17 + ```php
18 + use Doctrine\ORM\Mapping as ORM;
19 + use Ufo\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
20 + use Ufo\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
21 + use Ufo\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
22 + use Ufo\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
23 +
24 + #[ORM\Entity]
25 + class Article implements TimestampableInterface, SoftDeletableInterface
26 + {
27 + use TimestampableTrait;
28 + use SoftDeletableTrait;
29 +
30 + #[ORM\Id, ORM\GeneratedValue, ORM\Column]
31 + private ?int $id = null;
32 + }
33 + ```
34 +
35 + The `createdAt`, `updatedAt` and `deletedAt` columns appear in the mapping without any `#[ORM\Column]`; timestamps are filled in during `flush()`, and `$entityManager->remove($article)` only sets `deletedAt`.
36 +
37 + ## Behaviors
38 +
39 + | Behavior | Interface | Trait | What it adds |
40 + | --- | --- | --- | --- |
41 + | [Timestampable](/docs/doctrine/doctrine-behaviors/timestampable) | `TimestampableInterface` | `TimestampableTrait` | `createdAt`, `updatedAt` |
42 + | [Blameable](/docs/doctrine/doctrine-behaviors/blameable) | `BlameableInterface` | `BlameableTrait` | `createdBy`, `updatedBy`, `deletedBy` |
43 + | [SoftDeletable](/docs/doctrine/doctrine-behaviors/soft_deletable) | `SoftDeletableInterface` | `SoftDeletableTrait` | `deletedAt`, deletion without `DELETE` |
44 + | [Translatable](/docs/doctrine/doctrine-behaviors/translatable) | `TranslatableInterface`, `TranslationInterface` | `TranslatableTrait`, `TranslationTrait` | relation to the translation entity, `locale` |
45 + | [Sluggable](/docs/doctrine/doctrine-behaviors/sluggable) | `SluggableInterface` | `SluggableTrait` | `slug` |
46 + | [Tree](/docs/doctrine/doctrine-behaviors/tree) | `TreeNodeInterface` | `TreeNodeTrait`, `TreeTrait` (repository) | `materializedPath` |
47 + | [Uuidable](/docs/doctrine/doctrine-behaviors/uuidable) | `UuidableInterface` | `UuidableTrait` | `uuid` |
48 + | [Loggable](/docs/doctrine/doctrine-behaviors/loggable) | `LoggableInterface` | `LoggableTrait` | entries in a PSR-3 logger |
49 +
50 + Interfaces live in `Ufo\DoctrineBehaviors\Contract\Entity`, traits in `Ufo\DoctrineBehaviors\Model\<Behavior>`. Every trait except `LoggableTrait` is made of two: `...PropertiesTrait` (properties) and `...MethodsTrait` (methods) โ€” they can be used separately when you need to declare the properties your own way.
51 +
52 + The bundle adds a column only if a field with that name is not mapped yet, so you can set the type or length with your own mapping.
53 +
54 + ## Sections
55 +
56 + * [Installation](/docs/doctrine/doctrine-behaviors/installation)
57 + * [Configuration](/docs/doctrine/doctrine-behaviors/config) โ€” container parameters, custom user and locale providers.
58 + * Behaviors โ€” links in the table above.
59 + * [Changelog](/docs/doctrine/doctrine-behaviors/change_log)
60 + * [Known issues](/docs/doctrine/doctrine-behaviors/known_issues/open)

en/docs/doctrine/doctrine-behaviors/.info.md new file +19 โˆ’0

1 + [![Version](https://img.shields.io/packagist/v/ufo-tech/doctrine-behaviors?style=flat-square&label=version&color=5f3dc4)](/docs/doctrine/doctrine-behaviors/change_log)
2 + [![Downloads](https://img.shields.io/packagist/dt/ufo-tech/doctrine-behaviors?style=flat-square&label=downloads&color=2f5aa8)](https://packagist.org/packages/ufo-tech/doctrine-behaviors/stats)
3 + [![Stars](https://img.shields.io/github/stars/UFO-Tech/DoctrineBehaviors?style=flat-square&label=โ˜…&color=6b7785)](https://github.com/UFO-Tech/DoctrineBehaviors)
4 +
5 + ```bash
6 + composer require ufo-tech/doctrine-behaviors
7 + ```
8 +
9 + * **PHP** 8.4+
10 + * **Symfony** 7 ยท 8
11 + * **Built on** Doctrine ORM 3.7+ ยท DBAL 4.2+
12 + * **Type** Symfony Bundle
13 + * **Category** Doctrine
14 + * **License** MIT
15 +
16 + [GitHub](https://github.com/UFO-Tech/DoctrineBehaviors)
17 + [Packagist](https://packagist.org/packages/ufo-tech/doctrine-behaviors)
18 + [Changelog](/docs/doctrine/doctrine-behaviors/change_log)
19 + [Known issues](/docs/doctrine/doctrine-behaviors/known_issues/open)