/**
  * {@inheritDoc}
  */
 public function handleValidate(EntityMetadata $metadata)
 {
     $persistence = $metadata->persistence;
     $validIdStrategies = ['object'];
     if (!in_array($persistence->idStrategy, $validIdStrategies)) {
         throw MetadataException::invalidMetadata($metadata->type, sprintf('The persistence id strategy "%s" is invalid. Valid types are "%s"', $persistence->idStrategy, implode('", "', $validIdStrategies)));
     }
     if (false === $metadata->isChildEntity() && (empty($persistence->db) || empty($persistence->collection))) {
         throw MetadataException::invalidMetadata($metadata->type, 'The persistence database and collection names cannot be empty.');
     }
     if (false === $this->entityUtil->isEntityTypeValid($persistence->collection)) {
         throw MetadataException::invalidMetadata($metadata->type, sprintf('The entity persistence collection "%s" is invalid based on the configured name format "%s"', $persistence->collection, $this->entityUtil->getRestConfig()->getEntityFormat()));
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getMetadataForType($type)
 {
     if (null !== ($metadata = $this->doLoadMetadata($type))) {
         // Found in memory or from cache implementation
         return $metadata;
     }
     // Loop through the type hierarchy (extension) and merge metadata objects.
     foreach ($this->driver->getTypeHierarchy($type) as $hierType) {
         if (null !== ($loaded = $this->doLoadMetadata($hierType))) {
             // Found in memory or from cache implementation
             $this->mergeMetadata($metadata, $loaded);
             continue;
         }
         // Load from driver source
         $loaded = $this->driver->loadMetadataForType($hierType);
         if (null === $loaded) {
             throw MetadataException::mappingNotFound($type);
         }
         // Validate the metadata object.
         $this->entityUtil->validateMetadata($hierType, $loaded, $this);
         // Handle persistence specific loading and validation.
         $persisterKey = $loaded->persistence->getKey();
         $persistenceFactory = $this->driver->getPersistenceMetadataFactory($persisterKey);
         $persistenceFactory->handleLoad($loaded);
         $persistenceFactory->handleValidate($loaded);
         // Handle search specific loading and validation.
         $clientKey = $loaded->search->getKey();
         $searchFactory = $this->driver->getSearchMetadataFactory($clientKey);
         $searchFactory->handleLoad($loaded);
         $searchFactory->handleValidate($loaded);
         $this->mergeMetadata($metadata, $loaded);
         $this->doPutMetadata($loaded);
     }
     if (null === $metadata) {
         throw MetadataException::mappingNotFound($type);
     }
     $this->doPutMetadata($metadata);
     return $metadata;
 }