Completed
Push — ezp-30616 ( 3c2fb4...b64679 )
by
unknown
30:04 queued 14:26
created

BookmarkService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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