Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.1 KB

blameable.md

File metadata and controls

49 lines (33 loc) · 1.1 KB

Blameable

Blameable is able to track entity creators and updaters.

  • Knp\DoctrineBehaviors\Contract\Provider\UserProviderInterface

A Blameable callable is used to get the current user from your application.

In the case you are using a Doctrine Entity to represent your users, you can configure the subscriber to manage automatically the association between this user entity and your entites.

Using Symfony, all you have to do is to configure the DI parameter named %knp.doctrine_behaviors.blameable_subscriber.user_entity% with a fully qualified namespace, for example:

Entity

<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;

/**
 * @ORM\Entity
 */
class Category implements BlameableInterface
{
    use BlameableTrait;
}

Usage

Then, you can use it like that:

<?php

$category = new Category;
$entityManager->persist($category);

$creator = $category->getCreatedBy();
$updater = $category->getUpdatedBy();