/
BookmarkService.php
65 lines (49 loc) · 2.06 KB
/
BookmarkService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace eZ\Publish\Core\Event;
use eZ\Publish\API\Repository\BookmarkService as BookmarkServiceInterface;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Events\Bookmark\BeforeCreateBookmarkEvent;
use eZ\Publish\API\Repository\Events\Bookmark\BeforeDeleteBookmarkEvent;
use eZ\Publish\API\Repository\Events\Bookmark\CreateBookmarkEvent;
use eZ\Publish\API\Repository\Events\Bookmark\DeleteBookmarkEvent;
use eZ\Publish\SPI\Repository\Decorator\BookmarkServiceDecorator;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class BookmarkService extends BookmarkServiceDecorator
{
/** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
protected $eventDispatcher;
public function __construct(
BookmarkServiceInterface $innerService,
EventDispatcherInterface $eventDispatcher
) {
parent::__construct($innerService);
$this->eventDispatcher = $eventDispatcher;
}
public function createBookmark(Location $location): void
{
$eventData = [$location];
$beforeEvent = new BeforeCreateBookmarkEvent(...$eventData);
$this->eventDispatcher->dispatch($beforeEvent);
if ($beforeEvent->isPropagationStopped()) {
return;
}
$this->innerService->createBookmark($location);
$this->eventDispatcher->dispatch(new CreateBookmarkEvent(...$eventData));
}
public function deleteBookmark(Location $location): void
{
$eventData = [$location];
$beforeEvent = new BeforeDeleteBookmarkEvent(...$eventData);
$this->eventDispatcher->dispatch($beforeEvent);
if ($beforeEvent->isPropagationStopped()) {
return;
}
$this->innerService->deleteBookmark($location);
$this->eventDispatcher->dispatch(new DeleteBookmarkEvent(...$eventData));
}
}