Beispiel #1
0
 public function testValidationWithUnmappedPropertiesShouldThrowException()
 {
     $this->setExpectedException('Papper\\ValidationException');
     // arrange
     $typeMap = new TypeMap('SomeType', 'AnotherType', \Mockery::mock('Papper\\ObjectCreatorInterface'));
     $typeMap->addPropertyMap(self::createMappedProperty());
     $typeMap->addPropertyMap(self::createUnmappedProperty());
     // act
     $typeMap->validate();
 }
Beispiel #2
0
 public function createTypeMap($sourceType, $destinationType, MappingOptionsInterface $mappingOptions)
 {
     $sourceReflector = $this->findReflector($sourceType);
     $destReflector = $this->findReflector($destinationType);
     $typeMap = new TypeMap($sourceType, $destinationType, new SimpleObjectCreator($destReflector));
     /** @var $destMembers \ReflectionProperty[]|\ReflectionMethod[] */
     $destMembers = array_merge(ReflectionHelper::getPublicMethods($destReflector, 1), $destReflector->getProperties(\ReflectionProperty::IS_PUBLIC));
     foreach ($destMembers as $destMember) {
         if ($destMember instanceof \ReflectionMethod && $destMember->isConstructor()) {
             continue;
         }
         $sourceMembers = array();
         $setter = $this->memberAccessFactory->createMemberSetter($destMember, $mappingOptions);
         $getter = $this->mapDestinationMemberToSource($sourceMembers, $sourceReflector, $destMember->getName(), $mappingOptions) ? $this->memberAccessFactory->createMemberGetter($sourceMembers, $mappingOptions) : null;
         $typeMap->addPropertyMap(new PropertyMap($setter, $getter));
     }
     return $typeMap;
 }
Beispiel #3
0
 /**
  * Execute a custom function to the source and/or destination types after member mapping
  *
  * @param \Closure $func Callback for the source/destination types
  * @return $this
  */
 public function afterMap(\Closure $func)
 {
     $this->typeMap->setAfterMapFunc($func);
     return $this;
 }