PHPackages                             tourze/resource-manage-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/resource-manage-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/resource-manage-bundle
=============================

Symfony bundle for resource management and distribution system

1.0.1(6mo ago)02.2k6MITPHPCI passing

Since Apr 19Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/resource-manage-bundle)[ Packagist](https://packagist.org/packages/tourze/resource-manage-bundle)[ RSS](/packages/tourze-resource-manage-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (20)Versions (8)Used By (6)

Resource Management Bundle
==========================

[](#resource-management-bundle)

[![PHP Version](https://camo.githubusercontent.com/acffb6ae1962992d26e4466782832787e79504a6250f80d732c4283458b9f497/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75652e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/c27a457659b89ee4f1f80f7995c559dd37f2051bde7167ad25791e5c5c92cc8e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e2e737667)](#)[![Coverage](https://camo.githubusercontent.com/b3545ae1bcdb4ea486f71f87b43001e82dd21933bc8035d44601706c851265da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e737667)](#)

[English](README.md) | [中文](README.zh-CN.md)

A universal resource distribution and management framework that supports unified management and distribution of various resource types.

Installation
------------

[](#installation)

```
composer require tourze/resource-manage-bundle
```

系统概述
----

[](#系统概述)

资源管理系统是一个通用的资源发放和管理框架，支持多种类型资源的统一管理和分发。系统采用接口定义和依赖注入的方式，实现了高度的可扩展性和灵活性。

核心组件
----

[](#核心组件)

### 1. ResourceIdentity 接口

[](#1-resourceidentity-接口)

定义了资源的基本标识接口，包含：

- getResourceId(): 获取资源唯一标识
- getResourceLabel(): 获取资源显示名称

### 2. ResourceProvider 接口

[](#2-resourceprovider-接口)

资源提供者的统一接口，负责具体资源类型的管理和发放：

- getCode(): 资源类型的唯一标识
- getLabel(): 资源类型的显示名称
- getIdentities(): 获取该类型下所有可用的资源列表
- findIdentity(): 查找特定资源
- sendResource(): 发放资源给用户

### 3. ResourceManager 服务

[](#3-resourcemanager-服务)

资源管理器，负责：

- 统一管理所有资源提供者
- 提供资源选择数据
- 统一的资源发放入口

已实现的资源类型
--------

[](#已实现的资源类型)

### 1. 优惠券资源 (CouponResourceProvider)

[](#1-优惠券资源-couponresourceprovider)

- 类型标识：coupon
- 功能：管理和发放优惠券
- 特点：与优惠券系统集成，支持优惠券的查找和发放

### 2. 实物奖品资源 (SpuOfferResourceProvider)

[](#2-实物奖品资源-spuofferresourceprovider)

- 类型标识：material
- 功能：管理和发放实物商品
- 特点：与商品系统集成，支持商品库存管理和订单创建

### 3. 文本资源 (TextResourceProvider)

[](#3-文本资源-textresourceprovider)

- 类型标识：text
- 功能：用于发放文本类型的安慰奖
- 特点：无实际发放行为，用于安慰奖场景

### 4. 虚拟资源 (VirtualResourceProvider)

[](#4-虚拟资源-virtualresourceprovider)

- 类型标识：virtual
- 功能：用于发放虚拟奖品
- 特点：无实际发放行为，用于虚拟奖品场景

如何实现新的资源类型
----------

[](#如何实现新的资源类型)

1. 创建资源实体类并实现 ResourceIdentity 接口

```
class MyResource implements ResourceIdentity
{
    public function getResourceId(): string
    {
        return $this->id;
    }

    public function getResourceLabel(): string
    {
        return $this->name;
    }
}
```

2. 创建资源提供者类并实现 ResourceProvider 接口

```
use Symfony\Component\Security\Core\User\UserInterface;
use Tourze\ResourceManageBundle\Model\ResourceIdentity;
use Tourze\ResourceManageBundle\Service\ResourceProvider;

class MyResourceProvider implements ResourceProvider
{
    public function getCode(): string
    {
        return 'my_resource';
    }

    public function getLabel(): string
    {
        return '我的资源';
    }

    public function getIdentities(): iterable|null
    {
        // 返回所有可用资源
    }

    public function findIdentity(string $identity): ResourceIdentity|null
    {
        // 查找特定资源
    }

    public function sendResource(UserInterface $user, ?ResourceIdentity $identity, string $amount, int|float|null $expireDay = null, ?\DateTimeInterface $expireTime = null): void
    {
        // 实现资源发放逻辑
    }
}
```

3. 资源提供者会自动注册到系统中（通过 AutoconfigureTag 注解）

使用示例
----

[](#使用示例)

```
// 注入资源管理器
private ResourceManager $resourceManager;

// 发放资源
$this->resourceManager->send(
    $user,          // 用户
    'coupon',       // 资源类型
    'COUPON001',    // 资源ID
    '1',            // 数量
    30,             // 过期天数（可选）
    null            // 过期时间（可选）
);

// 获取所有可用资源类型
$resources = $this->resourceManager->genSelectData();
```

注意事项
----

[](#注意事项)

1. 资源类型的 Code 必须全局唯一
2. 实现新的资源类型时，需要同时实现资源标识和提供者
3. 资源发放时需要处理异常情况
4. 建议为新增的资源类型添加单元测试

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance71

Regular maintenance activity

Popularity16

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~34 days

Recently: every ~51 days

Total

7

Last Release

187d ago

Major Versions

0.1.1 → 1.0.02025-10-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-resource-manage-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-resource-manage-bundle/health.svg)](https://phpackages.com/packages/tourze-resource-manage-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
