adonko3xbitters/symfony-archivable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-07