/** * Loads a has-many embed collection. * * @param EmbeddedPropMetadata $relMeta * @param array|null $embedDocs * @return Collections\EmbedCollection */ public function createEmbedCollection(EmbeddedPropMetadata $embededPropMeta, array $embedDocs = null) { if (empty($embedDocs)) { $embedDocs = []; } if (false === $this->isSequentialArray($embedDocs)) { throw StoreException::badRequest(sprintf('Improper has-many data detected for embed "%s" - a sequential array is required.', $embededPropMeta->getKey())); } $embeds = []; foreach ($embedDocs as $embedDoc) { $embeds[] = $this->loadEmbed($embededPropMeta->embedMeta, $embedDoc); } return new Collections\EmbedCollection($embededPropMeta->embedMeta, $this, $embeds); }
/** * {@inheritdoc} */ protected function validateEmbed(EmbeddedPropMetadata $embed) { if (true === $this->hasAttribute($embed->getKey())) { throw MetadataException::fieldKeyInUse('embed', 'attribute', $embed->getKey(), $this->name); } }
/** * Sets the entity embed metadata from the metadata mapping. * * @param Metadata\Interfaces\EmbedInterface $metadata * @param array $embedMapping * @return Metadata\EntityMetadata */ protected function setEmbeds(Metadata\Interfaces\EmbedInterface $metadata, array $embedMapping) { foreach ($embedMapping as $key => $mapping) { if (!is_array($mapping)) { $mapping = ['type' => null, 'entity' => null]; } if (!isset($mapping['type'])) { $mapping['type'] = null; } if (!isset($mapping['entity'])) { $mapping['entity'] = null; } $embedMeta = $this->loadMetadataForEmbed($mapping['entity']); if (null === $embedMeta) { continue; } $property = new Metadata\EmbeddedPropMetadata($key, $mapping['type'], $embedMeta, $this->isMixin($metadata)); if (isset($mapping['serialize'])) { $property->enableSerialize($mapping['serialize']); } $metadata->addEmbed($property); } return $metadata; }