| @@ 23-56 (lines=34) @@ | ||
| 20 | /** |
|
| 21 | * Maps the node name. |
|
| 22 | */ |
|
| 23 | class NodeNameSubscriber implements EventSubscriberInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public static function getSubscribedEvents() |
|
| 29 | { |
|
| 30 | return [ |
|
| 31 | Events::HYDRATE => 'handleNodeName', |
|
| 32 | Events::PERSIST => 'handleNodeName', |
|
| 33 | ]; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @param AbstractMappingEvent $event |
|
| 38 | * |
|
| 39 | * @throws DocumentManagerException |
|
| 40 | */ |
|
| 41 | public function handleNodeName(AbstractMappingEvent $event) |
|
| 42 | { |
|
| 43 | $document = $event->getDocument(); |
|
| 44 | ||
| 45 | if (!$document instanceof NodeNameBehavior) { |
|
| 46 | return; |
|
| 47 | } |
|
| 48 | ||
| 49 | $node = $event->getNode(); |
|
| 50 | $accessor = $event->getAccessor(); |
|
| 51 | $accessor->set( |
|
| 52 | 'nodeName', |
|
| 53 | $node->getName() |
|
| 54 | ); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||
| @@ 23-57 (lines=35) @@ | ||
| 20 | /** |
|
| 21 | * Maps the UUID. |
|
| 22 | */ |
|
| 23 | class UuidSubscriber implements EventSubscriberInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public static function getSubscribedEvents() |
|
| 29 | { |
|
| 30 | return [ |
|
| 31 | Events::HYDRATE => 'handleUuid', |
|
| 32 | Events::PERSIST => ['handleUuid', 0], |
|
| 33 | ]; |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @param AbstractMappingEvent $event |
|
| 38 | * |
|
| 39 | * @throws DocumentManagerException |
|
| 40 | */ |
|
| 41 | public function handleUuid(AbstractMappingEvent $event) |
|
| 42 | { |
|
| 43 | $document = $event->getDocument(); |
|
| 44 | ||
| 45 | if (!$document instanceof UuidBehavior) { |
|
| 46 | return; |
|
| 47 | } |
|
| 48 | ||
| 49 | $node = $event->getNode(); |
|
| 50 | ||
| 51 | $accessor = $event->getAccessor(); |
|
| 52 | $accessor->set( |
|
| 53 | 'uuid', |
|
| 54 | $node->getIdentifier() |
|
| 55 | ); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||