ggggino / recenty-bundle
方便实现“最近使用”的功能的包
v1.0.2
2021-01-04 01:03 UTC
Requires
- php: ^7.2 || ^8.0
- doctrine/doctrine-bundle: ^2.0
- symfony/http-kernel: ^4.4 || ^5.1
Requires (Dev)
- phpunit/phpunit: ^8.4
- psr/cache: ^1.0
- psr/simple-cache: ^1.0
- symfony/phpunit-bridge: ^4.4 || ^5.1
Suggests
- psr/cache: To be used with GGGGino\RecentyBundle\Storage\StorageCache
- psr/simple-cache: To be used with GGGGino\RecentyBundle\Storage\StorageCache
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