承接 tito10047/persistent-state-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tito10047/persistent-state-bundle

Composer 安装命令:

composer require tito10047/persistent-state-bundle

包简介

Easily manage persistent checkbox selections and key-value settings in Symfony applications.

README 文档

README

Tests

Persistent State Bundle


This Symfony bundle provides a unified and robust solution for managing persistent user interface state. It handles two key areas:

  1. Selections: Efficient handling of bulk operations (e.g., "Select All" across multiple pages of a paginated list).
  2. Preferences: Storing key-value settings for various contexts (e.g., user, company).

It features a flexible architecture based on context resolvers and support for various storage backends (Session, Redis, Doctrine), allowing you to elegantly solve UI state persistence without boilerplate code in your controllers.

Features

  • Selection Management: Track selected items (IDs) across pagination.
  • Preference Management: Store and retrieve arbitrary user/context settings.
  • Context Resolvers: Automatically resolve context (e.g., current user) for storage.
  • Twig Integration: Easy-to-use Twig functions and filters.
  • Stimulus Integration: Ready-to-use Stimulus controller for interactive selections.
  • Multiple Storages: Support for Session (default), Doctrine, and easily extensible for others (e.g., Redis).
  • CLI Support: Debug preferences directly from the terminal.

Requirements

  • PHP: ^8.1
  • Symfony: ^6.4 | ^7.4 | ^8.0

Installation

Install the bundle via Composer:

composer require tito10047/persistent-state-bundle

If you are using Symfony Flex, the bundle will be registered automatically. Otherwise, add it to your config/bundles.php:

return [
    // ...
    Tito10047\PersistentStateBundle\PersistentStateBundle::class => ['all' => true],
];

For Stimulus integration, ensure you have Symfony UX Stimulus installed and configured.

Usage Scenarios

1. Simple Selection (e.g., Shopping Cart)

use Tito10047\PersistentStateBundle\Selection\Service\SelectionManagerInterface;

class CartController
{
    public function __construct(
        private readonly SelectionManagerInterface $selectionManager,
    ) {}

    public function add(User $user, Product $product)
    {
        $cartSelection = $this->selectionManager->getSelection( 'cart',$user);
        $cartSelection->select($product, [
            'quantity' => 1,
            'added_at' => new \DateTime()
        ]);
    }

    public function clear(User $user)
    {
        $this->selectionManager->getSelection('cart',$user)->destroy();
    }
}

2. User Preferences

use Tito10047\PersistentStateBundle\Preference\Service\PreferenceManagerInterface;

class SettingsController
{
    public function __construct(
        private readonly PreferenceManagerInterface $prefManager,
    ) {}

    public function updateTheme(User $user, string $theme)
    {
        $preferences = $this->prefManager->getPreference($user);
        $preferences->set('theme', $theme);
    }
}

In Twig:

<body class="theme-{{ preference(app.user, 'theme', 'light') }}">
    Company Setting: {{ company|pref('some_setting') }}
</body>

3. Bulk Actions with Stimulus

This bundle provides a Stimulus controller to handle "Select All" and individual row selections.

<div {{ persistent_selection_stimulus_controller("main_logs", null, {
    selectAllClass: 'btn-primary',
    unselectAllClass: 'btn-outline-secondary',
}) }}>
    <div class="mb-2">
        <button class="btn btn-sm" data-action="tito10047--persistent-state-bundle--selection#selectCurrentPage">
            Select Visible
        </button>
        <button class="btn btn-sm" data-action="tito10047--persistent-state-bundle--selection#selectAll">
            Select All
        </button>
    </div>

    <ul class="list-group">
        {% for log in logs %}
            <li class="list-group-item">
                {{ persistent_selection_row_selector("main_logs", log) }}
                {{ log.name }}
            </li>
        {% endfor %}
    </ul>
</div>

In your controller to perform the action:

public function deleteSelected(User $user)
{
    $selection = $this->selectionManager->getSelection('main_logs', $user);
    $ids = $selection->getSelectedIdentifiers();
    
    // ... perform deletion
}

Configuration

Default configuration (optional to override in config/packages/persistent_state.yaml):

persistent_state:
    preference:
        managers:
            default:
                storage: '@persistent_state.preference.storage.session'
    selection:
        managers:
            default:
                storage: '@persistent_state.selection.storage.session'

See docs/full_config.md for more advanced configuration, including Doctrine storage setup.

Console Commands

debug:preference

Inspect stored preferences for a specific context.

php bin/console debug:preference "user_15" --manager=default

Testing

Run tests using PHPUnit:

composer test

License

This bundle is released under the MIT License.

tito10047/persistent-state-bundle 适用场景与选型建议

tito10047/persistent-state-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 214 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「ui」 「pagination」 「batch」 「preference」 「symfony-ux」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tito10047/persistent-state-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tito10047/persistent-state-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 tito10047/persistent-state-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 214
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 29
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-09