PartKeepr\ImportBundle\Configuration\FieldConfiguration::parseConfiguration PHP Method

parseConfiguration() public method

public parseConfiguration ( $configuration )
    public function parseConfiguration($configuration)
    {
        if (!property_exists($configuration, "fieldConfiguration")) {
            return false;
            throw new \Exception("The key fieldConfiguration does not exist!");
        }
        if (!in_array($configuration->fieldConfiguration, self::fieldConfigurationModes)) {
            throw new \Exception("The key fieldConfiguration contains an invalid value!");
        }
        $this->fieldConfiguration = $configuration->fieldConfiguration;
        switch ($this->fieldConfiguration) {
            case self::FIELDCONFIGURATION_FIXEDVALUE:
                if (!property_exists($configuration, "setToValue")) {
                    throw new \Exception("The key setToValue does not exist for mode fixedValue!");
                }
                $this->fixedValue = $configuration->setToValue;
                break;
            case self::FIELDCONFIGURATION_COPYFROM:
                if (!property_exists($configuration, "copyFromField")) {
                    throw new \Exception("The key copyFromField does not exist for mode copyFrom!");
                }
                $this->copyFromField = $configuration->copyFromField;
                break;
            default:
                break;
        }
        return true;
    }

Usage Example

Beispiel #1
0
 public function parseConfiguration($importConfiguration)
 {
     if (property_exists($importConfiguration, "fields")) {
         foreach ($importConfiguration->fields as $field => $configuration) {
             if ($this->classMetadata->hasField($field)) {
                 $fieldConfiguration = new FieldConfiguration($this->classMetadata, $this->baseEntity, $this->reflectionService, $this->em, $this->advancedSearchFilter, $this->iriConverter);
                 $fieldConfiguration->setFieldName($field);
                 if ($fieldConfiguration->parseConfiguration($configuration) !== false) {
                     $this->fields[] = $fieldConfiguration;
                 }
             } else {
                 //throw new \Exception("Field $field not found in ".$this->baseEntity);
             }
         }
     }
     if (property_exists($importConfiguration, "manytoone")) {
         foreach ($importConfiguration->manytoone as $manyToOne => $configuration) {
             if ($this->classMetadata->hasAssociation($manyToOne)) {
                 $targetClass = $this->classMetadata->getAssociationTargetClass($manyToOne);
                 $cm = $this->em->getClassMetadata($targetClass);
                 $manyToOneconfiguration = new ManyToOneConfiguration($cm, $targetClass, $this->reflectionService, $this->em, $this->advancedSearchFilter, $this->iriConverter);
                 $manyToOneconfiguration->setAssociationName($manyToOne);
                 if ($manyToOneconfiguration->parseConfiguration($configuration) !== false) {
                     $this->manyToOneAssociations[] = $manyToOneconfiguration;
                 }
             } else {
                 //throw new \Exception("Association $manyToOne not found in ".$this->baseEntity);
             }
         }
     }
     if (property_exists($importConfiguration, "onetomany")) {
         foreach ($importConfiguration->onetomany as $oneToMany => $configuration) {
             if ($this->classMetadata->hasAssociation($oneToMany)) {
                 $targetClass = $this->classMetadata->getAssociationTargetClass($oneToMany);
                 $cm = $this->em->getClassMetadata($targetClass);
                 $oneToManyConfiguration = new OneToManyConfiguration($cm, $targetClass, $this->reflectionService, $this->em, $this->advancedSearchFilter, $this->iriConverter);
                 $oneToManyConfiguration->setAssociationName($oneToMany);
                 if ($oneToManyConfiguration->parseConfiguration($configuration) !== false) {
                     $this->oneToManyAssociations[] = $oneToManyConfiguration;
                 }
             } else {
                 //throw new \Exception("Association $oneToMany not found in ".$this->baseEntity);
             }
         }
     }
     return true;
 }