wwwision / likes
简单的Neos Flow包,允许跟踪任意“点赞”或推荐
1.0.0
2020-11-20 14:29 UTC
Requires
- neos/event-sourcing: ^2.0
- neos/flow: ^5.0
Requires (Dev)
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-09-20 23:33:58 UTC
README
简单的Neos Flow包,允许使用Event-Sourcing跟踪任意“点赞”或推荐。
安装
使用composer安装此包
composer require wwwision/likes
配置
事件存储
默认情况下,此包配置为使用DoctrineEventStorage
来存储事件,并使用默认选项。这意味着“点赞”事件将默认存储在数据库表neos_eventsourcing_eventstore_events
中。这可以通过几行Settings.yaml
进行更改。
Neos: EventSourcing: EventStore: stores: 'Wwwision.Likes:EventStore': storageOptions: eventTableName: 'wwwision_like_events'
之后,应通过以下方式设置事件存储:
./flow eventstore:setup Wwwision.Likes:EventStore
元数据 / GDPR
默认情况下,此包发布的所有事件都将包含元数据,其中包含有关当前活动的HTTP请求的详细信息,包括请求URL、方法、userAgent和clientIP头。
此行为可以通过Settings.yaml
进行调整。
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
使用方法
从PHP使用提供的LikeService
添加/撤销点赞,以及检索现有点赞的详细信息。该服务应该是自解释的,但不建议直接使用。相反,它应该被包装在某个更具体于实际域的服务中。
示例
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()); } }