/** * @param $command * @param $entity * @param bool $addExtractedEntity * * @return Result */ protected function createResult($command, $entity, $addExtractedEntity = true) { $meta = $this->objectManager->getClassMetadata($this->className); $identifiers = $meta->getIdentifierValues($entity); $result = new Result($command, current($identifiers)); if (!$addExtractedEntity) { return $result; } $data = $this->hydrator->extract($entity); $result->addParams(['item' => $data]); return $result; }
/** * @param $command * @param $params * * @return Result */ protected function handleCommand($command, $params) { try { $event = new BulkEvent($command, $this, $params); $response = $this->getEventManager()->trigger($event, function ($result) { return $result instanceof Result; }); $result = $response->last(); if (!$response->stopped()) { throw new \Exception(sprintf('Unknown bulk command %s', $command)); } } catch (\Exception $e) { $id = isset($params['id']) ? $params['id'] : 'unknown'; $result = new Result($command, $id); $result->setError($e->getMessage()); } return $result; }