dev-master
9999999-devSimple Neos Flow package that allows to track arbitrary "likes" or recommendations
The Requires
Simple Neos Flow package that allows to track arbitrary "likes" or recommendations
Simple Neos Flow package that allows to track arbitrary "likes" or recommendations using Event-Sourcing., (*1)
Install this package using composer:, (*2)
composer require wwwision/likes
By default, this package is configured to use the DoctrineEventStorage
to store events with the default options.
This means, that "like"-events will be stored in a database table neos_eventsourcing_eventstore_events
by default.
This can be changed with a few lines of Settings.yaml
:, (*3)
Neos: EventSourcing: EventStore: stores: 'Wwwision.Likes:EventStore': storageOptions: eventTableName: 'wwwision_like_events'
Afterwards the Event Store should be set-up via, (*4)
./flow eventstore:setup Wwwision.Likes:EventStore
By default all events published by this package will contain metadata that contains details about the currently active HTTP request including request URL, method, userAgent and clientIP headers., (*5)
This behavior can be adjusted via Settings.yaml
:, (*6)
Wwwision: Likes: eventMetadata: # disable tracking of absolute HTTP request URL url: true # disable tracking of HTTP request Method (GET, POST, ...) method: true # disable tracking of users IP address clientIpAddress: true # disable tracking of browsers "userAgent" header userAgent: true
From PHP use the provided LikeService
to add/revoke likes and to retrieve details about existing likes.
The service should be mostly self-explanatory, but it isn't meant to be used directly. Instead, it should be wrapped
in some service that is more specific to the actual domain., (*7)
final class FavoriteCoffeeBeans { private LikeService $likeService; private User $authenticatedUser; public function __construct(LikeService $likeService, User $authenticatedUser) { $this->likeService = $likeService; $this->authenticatedUser = $authenticatedUser; } public function addCoffeeBean(CoffeeBean $coffeeBean): void { $this->likeService->addLike('CoffeeBeans', (string)$this->authenticatedUser->getId(), (string)$coffeeBean->getId()); } public function removeCoffeeBean(CoffeeBean $coffeeBean): void { $this->likeService->revokeLike('CoffeeBeans', (string)$this->authenticatedUser->getId(), (string)$coffeeBean->getId()); } public function contains(CoffeeBean $coffeeBean): bool { return $this->likeService->likeExists('CoffeeBeans', (string)$this->authenticatedUser->getId(), (string)$coffeeBean->getId()); } }
Simple Neos Flow package that allows to track arbitrary "likes" or recommendations