/**
  * Creates the property mapping from the read annotation and configured mapping.
  *
  * @param object $obj The object.
  * @param \Vich\UploaderBundle\Annotation\UploadableField $field The read annotation.
  * @return PropertyMapping The property mapping.
  * @throws \InvalidArgumentException
  */
 protected function createMapping($obj, UploadableField $field)
 {
     $class = $this->adapter->getReflectionClass($obj);
     if (!array_key_exists($field->getMapping(), $this->mappings)) {
         throw new \InvalidArgumentException(sprintf('No mapping named "%s" configured.', $field->getMapping()));
     }
     $config = $this->mappings[$field->getMapping()];
     $mapping = new PropertyMapping();
     $mapping->setProperty($class->getProperty($field->getPropertyName()));
     $mapping->setFileNameProperty($class->getProperty($field->getFileNameProperty()));
     $mapping->setMappingName($field->getMapping());
     $mapping->setMapping($config);
     if ($config['namer']) {
         $mapping->setNamer($this->container->get($config['namer']));
     }
     return $mapping;
 }
 /**
  * Creates the property mapping from the read annotation and configured mapping.
  *
  * @param object $obj         The object.
  * @param string $fieldName   The field name.
  * @param array  $mappingData The mapping data.
  *
  * @return PropertyMapping           The property mapping.
  * @throws \InvalidArgumentException
  */
 protected function createMapping($obj, $fieldName, array $mappingData)
 {
     if (!array_key_exists($mappingData['mapping'], $this->mappings)) {
         throw new \InvalidArgumentException(sprintf('No mapping named "%s" configured.', $mappingData['mapping']));
     }
     $config = $this->mappings[$mappingData['mapping']];
     $fileProperty = isset($mappingData['propertyName']) ? $mappingData['propertyName'] : $fieldName;
     $fileNameProperty = empty($mappingData['fileNameProperty']) ? $fileProperty . $this->defaultFilenameAttributeSuffix : $mappingData['fileNameProperty'];
     $mapping = new PropertyMapping($fileProperty, $fileNameProperty);
     $mapping->setMappingName($mappingData['mapping']);
     $mapping->setMapping($config);
     if ($config['namer']) {
         $mapping->setNamer($this->container->get($config['namer']));
     }
     if ($config['directory_namer']) {
         $mapping->setDirectoryNamer($this->container->get($config['directory_namer']));
     }
     return $mapping;
 }
 /**
  * Creates the property mapping from the read annotation and configured mapping.
  *
  * @param object $obj         The object.
  * @param string $fieldName   The field name.
  * @param array  $mappingData The mapping data.
  *
  * @return PropertyMapping           The property mapping.
  * @throws MappingNotFoundException
  */
 protected function createMapping($obj, $fieldName, array $mappingData)
 {
     if (!array_key_exists($mappingData['mapping'], $this->mappings)) {
         throw MappingNotFoundException::createNotFoundForClassAndField($mappingData['mapping'], $this->getClassName($obj), $fieldName);
     }
     $config = $this->mappings[$mappingData['mapping']];
     $fileProperty = isset($mappingData['propertyName']) ? $mappingData['propertyName'] : $fieldName;
     $fileNameProperty = empty($mappingData['fileNameProperty']) ? $fileProperty . $this->defaultFilenameAttributeSuffix : $mappingData['fileNameProperty'];
     $mapping = new PropertyMapping($fileProperty, $fileNameProperty);
     $mapping->setMappingName($mappingData['mapping']);
     $mapping->setMapping($config);
     if ($config['namer']['service']) {
         $namerConfig = $config['namer'];
         $namer = $this->container->get($namerConfig['service']);
         if (!empty($namerConfig['options']) && $namer instanceof ConfigurableInterface) {
             $namer->configure($namerConfig['options']);
         } else {
             if (!empty($namerConfig['options']) && !$namer instanceof ConfigurableInterface) {
                 throw new \LogicException(sprintf('Namer %s can not receive options as it does not implement ConfigurableInterface.', $namerConfig['service']));
             }
         }
         $mapping->setNamer($namer);
     }
     if ($config['directory_namer']) {
         $mapping->setDirectoryNamer($this->container->get($config['directory_namer']));
     }
     return $mapping;
 }