Skip to content
Permalink
Browse files

Fixed validation condition

  • Loading branch information...
slava-v committed May 22, 2018
1 parent 3012777 commit 3a889a80fb592ebf34a98274bb9d1c3221089ffd
Showing with 30 additions and 30 deletions.
  1. +30 −30 Adminomatic/AutoMapper/Mapper.php
@@ -80,23 +80,23 @@ public function Map($destination, $source) {
return null;
}
/**
* Validates mapping configuration
*
* @throws \Exception
*/
private function validateConfiguration(){
/** @var Map $mapping */
foreach($this->maps as $key => $mapping){
if (empty($mapping->ForMember)){
throw new \Exception('Invalid Automapper configuration. The ForMember must be a valid FullNameSpace\ClassName::PropertyName');
} elseif ( empty($mapping->FromMember)
&& ( empty($mapping->ValueResolver)
|| (! empty($mapping->ValueResolver) && !$mapping instanceof IValueResolver) ) ) {
throw new \Exception('Invalid Automapper configuration. You must specify the FromMember, a valid FullNameSpace\ClassName::PropertyName OR a instance of IValueResolver');
}
}
}
/**
* Validates mapping configuration
*
* @throws \Exception
*/
private function validateConfiguration(){
/** @var Map $mapping */
foreach($this->maps as $key => $mapping){
if (empty($mapping->ForMember)){
throw new \Exception('Invalid Automapper configuration. The ForMember must be a valid FullNameSpace\ClassName::PropertyName');
} elseif ( empty($mapping->FromMember)
&& ( empty($mapping->ValueResolver)
|| (! empty($mapping->ValueResolver) && !$mapping->ValueResolver instanceof IValueResolver) ) ) {
throw new \Exception('Invalid Automapper configuration. You must specify the FromMember, a valid FullNameSpace\ClassName::PropertyName OR a instance of IValueResolver');
}
}
}
private function MapMapping(Map $map, \ReflectionProperty $destinationProperty, $source){
if($map->FromMember !== null) {
@@ -121,25 +121,25 @@ private function MapObject($destination, $source) {
return $source;
}
$sourceType = get_class($source);
$sourceType = get_class($source);
$destinationReflection = new \ReflectionClass($destination);
foreach($destinationReflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $destinationProperty) {
$map = null;
if($this->TryGetMap($destinationProperty, $map)) {
if($this->TryGetMap($destinationProperty, $map)) {
if (! ($map->FromMember) || $map->FromMember->Class == $sourceType){
$destination->{$destinationProperty->name} = $this->MapMapping($map, $destinationProperty, $source);
continue;
}
}else{
if (! ($map->FromMember) || $map->FromMember->Class == $sourceType){
$destination->{$destinationProperty->name} = $this->MapMapping($map, $destinationProperty, $source);
continue;
}
}else{
$srcProperty = null;
if(self::TryGetReflectionProperty($destinationProperty->name, $source, $srcProperty)) {
$destination->{$destinationProperty->name} = $this->MapProperty($destinationProperty, $srcProperty->getValue($source));
continue;
}
}
$srcProperty = null;
if(self::TryGetReflectionProperty($destinationProperty->name, $source, $srcProperty)) {
$destination->{$destinationProperty->name} = $this->MapProperty($destinationProperty, $srcProperty->getValue($source));
continue;
}
}
}
return $destination;
}

0 comments on commit 3a889a8

Please sign in to comment.
You can’t perform that action at this time.