Esempio n. 1
0
 /**
  * Create configuration for individual dynamic member
  *
  * @param string $name Destination member name
  * @param MemberOptionInterface|MemberOptionInterface[] $memberOptions Member option
  * @throws PapperConfigurationException
  * @return MappingFluentSyntax
  */
 public function forDynamicMember($name, $memberOptions = null)
 {
     $propertyMap = $this->typeMap->getPropertyMap($name);
     if ($propertyMap !== null) {
         throw new PapperConfigurationException(sprintf('Unable to create dynamic destination member %s on type %s because it already exists in type', $name, $this->typeMap->getDestinationType()));
     }
     $setter = $this->typeMap->getDestinationType() === 'stdClass' ? new StdClassPropertySetter($name) : new PropertyAccessSetter($name);
     $this->typeMap->addPropertyMap($propertyMap = new PropertyMap($setter));
     $memberOptions = is_array($memberOptions) ? $memberOptions : array($memberOptions);
     foreach ($memberOptions as $memberOption) {
         if (!$memberOption instanceof MemberOptionInterface) {
             throw new PapperConfigurationException('Member options must be array or instance of Papper\\MemberOptionInterface');
         }
         $memberOption->apply($this->typeMap, $propertyMap);
     }
     return $this;
 }