2017 © Pedro Peláez
 

library watcher

Allows to track changes on doctrine entities with an easy-to-use API.

image

dsentker/watcher

Allows to track changes on doctrine entities with an easy-to-use API.

  • Wednesday, September 20, 2017
  • by dsentker
  • Repository
  • 1 Watchers
  • 2 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

Watcher

GitHub release Packagist Maintenance, (*1)

Allows to track changes on doctrine entities with an easy-to-use and highly customizable API., (*2)

Documentation

View Documentation, (*3)

Quick example

You can use this library to track changes to Doctrine Entities. Use annotations to define the fields that you want to monitor. They determine where the changes are to be saved., (*4)

// User Entity class
/**
 * @Column(type="string")
 * @WatchedField // <-- Watcher now tracks changes related to this field
 */
protected string $emailAddress;

/**
 * @var $dbParams array
 * @var $config Configuration
 */
$em = EntityManager::create($dbParams, $config, Watcher::createEventManager(new DatabaseHandler()));
Watcher::registerAnnotations();


/** @var $user User */
$user = $em->getRepository(User::class)->find(1);
$user->setUsername("A new username");
$em->persist($user);
$em->flush();

/** @var EntityLogRepository $logRepo */
$logRepo = $em->getRepository(EntityLog::class);

/** @var EntityLog[] $changes */
$changes = $logRepo->getLogsFromEntity($user);

$lastChange = $changes[0];
echo vsprintf("Last updated at (%s): Changed %s from '%s' to '%s'", [
    $lastChange->getChangedAt()->format('Y-m-d'),
    $lastChange->getFieldLabel(),
    $lastChange->getOldValue(),
    $lastChange->getNewValue(),
]); // Last updated at 2017-09-07: Changed Email Address from 'foo@example.com' to 'foo42@example.com' 

Symfony4 services.yaml integration (example)


watcher.db_handler: class: App\Utils\AppWatcherHandler #your handler, e.g. Database Handler autowire: true Watcher\EventListener\FlushListener: calls: - method: pushUpdateHandler arguments: - '@watcher.db_handler' - method: setAnnotationReader arguments: - '@annotations.reader' tags: - { name: doctrine.event_listener, event: onFlush } Watcher\EventListener\LoadListener: arguments: - 'App\Entity\EntityLog' # The entity which relates to EntityLogRepository tags: - { name: doctrine.event_listener, event: postLoad }

, (*5)

Known Limitations

  • This package is able to track changes on single fields and associations (collections), but depends on the concept of Doctrine, which is limited to track changes on fields on the owning side. That means, that inverse side associations (@OneToMany) are NOT supported. @ManyToMany and @ManyToOne associations are supported.
  • Also consider the overhead. If you've chosen the DatabaseHandler, each tracked entity change results in a single database request.

, (*6)

Testing

TBD (support is appreciated!), (*7)

Credits

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub., (*8)

ToDo

  • Use interfaces for everything
  • Easy Symfony integration
  • Write tests
  • Optimize performance (group changes?)

External Libraries

This library depends on Doctrine (surprise!) and subpackages., (*9)

Watcher is licensed for use under the MIT License (MIT). Please see LICENSE for more information., (*10)

The Versions

20/09 2017

dev-master

9999999-dev

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

19/09 2017

0.2.51

0.2.51.0

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

15/09 2017

0.2.5

0.2.5.0

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

12/09 2017

0.2.43

0.2.43.0

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

12/09 2017

0.2.42

0.2.42.0

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

12/09 2017

0.2.41

0.2.41.0

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

12/09 2017

0.2.4

0.2.4.0

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

11/09 2017

0.2.1

0.2.1.0

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

11/09 2017

0.1.9

0.1.9.0

Allows to track changes on doctrine entities with an easy-to-use API.

  Sources   Download

MIT

The Requires

 

08/09 2017

0.1.5

0.1.5.0

Allows to track changes on doctrine entities with an easy-to-use and highly customizable API.

  Sources   Download

MIT

The Requires

 

08/09 2017

0.1.4

0.1.4.0

Allows to track changes on doctrine entities with an easy-to-use and highly customizable API.

  Sources   Download

MIT

The Requires

 

08/09 2017

0.1.3

0.1.3.0

Allows to track changes on doctrine entities with an easy-to-use and highly customizable API.

  Sources   Download

MIT

The Requires

 

08/09 2017

0.1.0

0.1.0.0

Allows to track changes on doctrine entities with an easy-to-use and highly customizable API.

  Sources   Download

MIT

The Requires