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

parseConfiguration() public method

public parseConfiguration ( $importConfiguration )
    public function parseConfiguration($importConfiguration)
    {
        if (!property_exists($importConfiguration, "importBehaviour")) {
            return false;
            throw new \Exception("The key importBehaviour does not exist!");
        }
        if (!in_array($importConfiguration->importBehaviour, self::importBehaviours)) {
            throw new \Exception("The key importBehaviour contains an invalid value!");
        }
        $this->importBehaviour = $importConfiguration->importBehaviour;
        switch ($this->importBehaviour) {
            case self::IMPORTBEHAVIOUR_ALWAYSSETTO:
                if (!property_exists($importConfiguration, "setToEntity")) {
                    throw new \Exception("The key setToEntity does not exist for mode alwaysSetTo!");
                }
                // @todo Check if setToEntity contains a valid value
                $this->setToEntity = $importConfiguration->setToEntity;
                break;
            case self::IMPORTBEHAVIOUR_MATCHDATA:
                if (!property_exists($importConfiguration, "matchers")) {
                    throw new \Exception("No matchers defined");
                }
                if (!is_array($importConfiguration->matchers)) {
                    throw new \Exception("matchers must be an array");
                }
                foreach ($importConfiguration->matchers as $matcher) {
                    if (!property_exists($matcher, "matchField") || !property_exists($matcher, "importField") || $matcher->importField == "") {
                        throw new \Exception("matcher configuration error");
                    }
                }
                $this->matchers = $importConfiguration->matchers;
                if (!property_exists($importConfiguration, "updateBehaviour")) {
                    throw new \Exception("The key updateBehaviour does not exist for mode copyFrom!");
                }
                if (!in_array($importConfiguration->updateBehaviour, self::updateBehaviours)) {
                    throw new \Exception("Invalid value for updateBehaviour");
                }
                $this->updateBehaviour = $importConfiguration->updateBehaviour;
                if (!property_exists($importConfiguration, "notFoundBehaviour")) {
                    throw new \Exception("The key notFoundBehaviour does not exist for mode copyFrom!");
                }
                if (!in_array($importConfiguration->notFoundBehaviour, self::notFoundBehaviours)) {
                    throw new \Exception("Invalid value for notFoundBehaviour");
                }
                $this->notFoundBehaviour = $importConfiguration->notFoundBehaviour;
                if ($this->notFoundBehaviour == self::NOTFOUNDBEHAVIOUR_SETTOENTITY) {
                    if (!property_exists($importConfiguration, "notFoundSetToEntity")) {
                        throw new \Exception("The key notFoundSetToEntity does not exist for mode copyFrom!");
                    }
                    // @todo check if notFoundSetToEntity contains a valid entity
                    $this->notFoundSetToEntity = $importConfiguration->notFoundSetToEntity;
                }
                break;
            default:
                break;
        }
        return parent::parseConfiguration($importConfiguration);
    }

Usage Example

Exemplo n.º 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;
 }