PHP code example of tourze / resource-manage-bundle

1. Go to this page and download the library: Download tourze/resource-manage-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / resource-manage-bundle example snippets


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

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

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
    {
        // 实现资源发放逻辑
    }
}

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

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

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