adonko3xbitters/symfony-archivable
最新稳定版本:1.0.0
Composer 安装命令:
composer require adonko3xbitters/symfony-archivable
包简介
A reusable Symfony trait for archiving entities using Doctrine filters.
README 文档
README
A lightweight Symfony package that provides a reusable Archivable trait and a Doctrine filter to automatically exclude archived entities from queries.
📦 Installation
Install the package via Composer:
composer require adonko3xBitters/symfony-archivable
🚀 Features
- Easily mark entities as archived using a single trait.
- Automatically exclude archived records from Doctrine queries.
- Enable or disable the filter at runtime.
🧑💻 Usage/Examples
1. Use the Archivable trait in your entities
use adonko3xBitters\SymfonyArchivable\Archivable; #[ORM\Entity] class Article { use Archivable; // other properties... }
2. Register the Doctrine filter in your configuration
In config/packages/doctrine.yaml:
doctrine: orm: filters: archived: class: adonko3xBitters\SymfonyArchivable\Doctrine\ArchivedFilter enabled: true
3. Archive an entity
To archive an entity, simply set the archivedAt property:
$article->setArchivedAt(new \DateTimeImmutable()); $entityManager->flush();
4. Doctrine queries will exclude archived entities by default
The filter automatically applies archived_at IS NULL to all entities using the Archivable trait.
5. Disable the filter manually (when needed)
If you want to include archived entities in a specific query:
$entityManager = $this->getDoctrine()->getManager(); $entityManager->getFilters()->disable('archived'); // perform query including archived entities... $entityManager->getFilters()->enable('archived');
📂 Directory Structure
src/ ├── Archivable.php └── Doctrine/ └── ArchivedFilter.php
📄 License
This package is open-sourced software licensed under the MIT license.
👤 Authors
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-07