ggggino/recenty-bundle

Bundle to facilitate the 'recently use of something'

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

This package is auto-updated.

Last update: 2024-03-04 08:03:53 UTC


README

Bundle that automize the favourite entity usage.

This bundle answer aim to resolve the question, how many times this thing is used.

Install

composer require ggggino/recenty-bundle

Configuration

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 permit to instantiate a object every time it is called

recenty_bundle.yaml

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

You can use as many client you like.

Usage

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!'
    ]);
}

Reference

Strategies

Strategy is the way a Entity will be stored and retrivied

Storages

Storage is the place where the Entity will be stored

Contribute

Test

./vendor/bin/simple-phpunit

TODO