private function checkAliasOrClass($aliasOrClass, $document)
 {
     if ($this->metadataFactory->hasAlias($aliasOrClass)) {
         $class = $this->metadataFactory->getMetadataForAlias($aliasOrClass)->getClass();
     } elseif (!class_exists($aliasOrClass)) {
         throw new DocumentManagerException(sprintf('Unknown class specified and no alias exists for "%s", known aliases: "%s"', $aliasOrClass, implode('", "', $this->metadataFactory->getAliases())));
     } else {
         $class = $aliasOrClass;
     }
     if (get_class($document) !== $class) {
         throw new DocumentNotFoundException(sprintf('Requested document of type "%s" but got document of type "%s"', $aliasOrClass, get_class($document)));
     }
 }
Пример #2
0
 /**
  * Bind data array to given document.
  *
  * TODO this logic have to be extracted in a proper way.
  *
  * @param CustomUrlDocument $document
  * @param array $data
  * @param string $locale
  */
 private function bind(CustomUrlDocument $document, $data, $locale)
 {
     $document->setTitle($data['title']);
     unset($data['title']);
     $metadata = $this->metadataFactory->getMetadataForAlias('custom_url');
     $accessor = PropertyAccess::createPropertyAccessor();
     foreach ($metadata->getFieldMappings() as $fieldName => $mapping) {
         if (!array_key_exists($fieldName, $data)) {
             continue;
         }
         $value = $data[$fieldName];
         if (array_key_exists('type', $mapping) && $mapping['type'] === 'reference') {
             $value = $this->documentManager->find($value['uuid'], $locale, ['load_ghost_content' => true]);
         }
         $accessor->setValue($document, $fieldName, $value);
     }
     $document->setLocale($locale);
 }
 /**
  * @param mixed $event
  */
 public function handleCreate(CreateEvent $event)
 {
     $metadata = $this->metadataFactory->getMetadataForAlias($event->getAlias());
     $document = $this->instantiateFromMetadata($metadata);
     $event->setDocument($document);
 }
 /**
  * {@inheritdoc}
  */
 public function getMetadataForAlias($alias)
 {
     return $this->metadataFactory->getMetadataForAlias($alias);
 }