| @@ 14-59 (lines=46) @@ | ||
| 11 | /** |
|
| 12 | * Sets the base path for the node. |
|
| 13 | */ |
|
| 14 | class BasePathSubscriber implements EventSubscriberInterface |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @var NodeManager |
|
| 18 | */ |
|
| 19 | private $nodeManager; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @var string |
|
| 23 | */ |
|
| 24 | private $basePath; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @param NodeManager $nodeManager |
|
| 28 | * @param string $basePath |
|
| 29 | */ |
|
| 30 | public function __construct( |
|
| 31 | NodeManager $nodeManager, |
|
| 32 | $basePath |
|
| 33 | ) { |
|
| 34 | $this->nodeManager = $nodeManager; |
|
| 35 | $this->basePath = $basePath; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * {@inheritdoc} |
|
| 40 | */ |
|
| 41 | public static function getSubscribedEvents() |
|
| 42 | { |
|
| 43 | return [ |
|
| 44 | Events::PERSIST => ['handlePersist', 500], |
|
| 45 | ]; |
|
| 46 | } |
|
| 47 | ||
| 48 | public function handlePersist(PersistEvent $event) |
|
| 49 | { |
|
| 50 | $document = $event->getDocument(); |
|
| 51 | ||
| 52 | if (!$document instanceof BasePathBehavior) { |
|
| 53 | return; |
|
| 54 | } |
|
| 55 | ||
| 56 | $parentNode = $this->nodeManager->createPath($this->basePath); |
|
| 57 | $event->setParentNode($parentNode); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 23-66 (lines=44) @@ | ||
| 20 | /** |
|
| 21 | * Remove subscriber. |
|
| 22 | */ |
|
| 23 | class RemoveSubscriber implements EventSubscriberInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * @var DocumentRegistry |
|
| 27 | */ |
|
| 28 | private $documentRegistry; |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @var NodeManager |
|
| 32 | */ |
|
| 33 | private $nodeManager; |
|
| 34 | ||
| 35 | public function __construct( |
|
| 36 | DocumentRegistry $documentRegistry, |
|
| 37 | NodeManager $nodeManager |
|
| 38 | ) { |
|
| 39 | $this->documentRegistry = $documentRegistry; |
|
| 40 | $this->nodeManager = $nodeManager; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * {@inheritdoc} |
|
| 45 | */ |
|
| 46 | public static function getSubscribedEvents() |
|
| 47 | { |
|
| 48 | return [ |
|
| 49 | Events::REMOVE => ['handleRemove', 500], |
|
| 50 | ]; |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Remove the given documents node from PHPCR session and optionally |
|
| 55 | * remove any references to the node. |
|
| 56 | * |
|
| 57 | * @param RemoveEvent $event |
|
| 58 | */ |
|
| 59 | public function handleRemove(RemoveEvent $event) |
|
| 60 | { |
|
| 61 | $document = $event->getDocument(); |
|
| 62 | $node = $this->documentRegistry->getNodeForDocument($document); |
|
| 63 | ||
| 64 | $node->remove(); |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||