<?phpnamespace App\Document;use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;use JsonSerializable;/** * @MongoDB\Document(repositoryClass="App\Repository\InventoryRepository", collection="inventory") * @MongoDB\UniqueIndex(keys={"gitId"="asc"}) */class Inventory implements JsonSerializable, SyncDocument{ const GIT_FIELDS = ['list']; const GIT_ID = 'gitId'; /** * @MongoDB\Id */ protected $_id; /** * @var string * @MongoDB\Field(type="string") */ protected $gitId; /** * @var array * @MongoDB\Field(type="collection") */ private $placements = []; /** * @var int * @MongoDB\Field(type="int") */ protected $placementCount; /** * @return mixed */ public function getId() { return $this->_id; } /** * @return mixed */ public function getGitId() { return $this->gitId; } /** * @param string $id * @return Inventory */ public function setGitId(string $id) { $this->gitId = $id; return $this; } /** * @return array */ public function getPlacements(): array { return $this->placements; } /** * @param array $placements * @return Inventory */ public function setPlacements(array $placements): Inventory { $this->placements = $placements; $this->setPlacementCount(count($placements)); return $this; } /** * @return int */ public function getPlacementCount(): int { return $this->placementCount; } /** * @param int $placementCount * @return Inventory */ private function setPlacementCount(int $placementCount): Inventory { $this->placementCount = $placementCount; return $this; } public function jsonSerialize() { return [ 'id' => $this->getId(), 'gitId' => $this->getGitId(), 'list' => $this->getPlacements(), 'placementCount' => $this->getPlacementCount(), ]; } public function gitSerialize() { return [ 'name' => $this->getGitId(), 'list' => $this->getPlacements() ]; } public function gitUnserialize(array $gitData): Inventory { return $this->setPlacements($gitData['list']); } public function validateMutation(Mutation $m) { return $m->getOldValue()['list'] === $this->getPlacements(); }}