ggggino/recenty-bundle

方便实现“最近使用”的功能的包

安装: 1

依赖: 0

建议: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v1.0.2 2021-01-04 01:03 UTC

This package is auto-updated.

Last update: 2024-09-04 08:56:26 UTC


README

自动化收藏实体使用的包

此包旨在解决一个问题:这个实体被使用了多少次。

安装

composer require ggggino/recenty-bundle

配置

services.yaml

services:
    ...
    GGGGino\RecentyBundle\Storage\StorageVolatile:
        shared: false

    app.strategy.desc:
        class: GGGGino\RecentyBundle\Strategy\StrategyDesc
        shared: false
        arguments: ['@GGGGino\RecentyBundle\Storage\StorageVolatile']

    app.strategy.asc:
        class: GGGGino\RecentyBundle\Strategy\StrategyAsc
        shared: false
        arguments: ['@GGGGino\RecentyBundle\Storage\StorageVolatile']

shared: false 允许每次调用时实例化一个对象

recenty_bundle.yaml

ggggino_recenty:
  clients:
    main:
      class: 'app.strategy.desc'
    slave:
      class: 'app.strategy.asc'

你可以使用你喜欢的任意多个客户端。

使用方法

use GGGGino\RecentyBundle\WrapperManager;

/**
 * @Route("/default", name="default")
 */
public function index(WrapperManager $wrapperManager): Response
{
    $strategies = $wrapperManager->getStrategies();
    
    /** @var Product $product */
    $product = $em->getRepository(Product::class)->find(1);

    try {
        $wrapperManager->increment('main', new WrapperGenericEntity($product, 'bought', 2));
    } catch (EntityNotValidException $e) {
        return $this->json([
            'message' => 'Wrapper not generable!'
        ], 500);
    }
    
    return $this->json([
        'message' => 'Welcome to your new controller!'
    ]);
}

参考

策略

策略是实体存储和检索的方式

存储

存储是实体将被存储的地方

贡献

测试

./vendor/bin/simple-phpunit

待办事项