Last active
February 9, 2016 18:42
-
-
Save alborq/92b19bf841ebdcadc656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mapperConfiguration = new MapperConfiguration(); | |
static class MapperCallableHelper{ | |
protected static $attributName = ""; | |
protected static $setterCallable = function(Mapper $mapper, $object, $value){ | |
$method = 'set'.ucfirst(self::$attributName); | |
$object->$method($value); | |
}; | |
protected static $isCallable = function(Mapper $mapper, $object, $value){ | |
$method = self::$attributName.'Is'; | |
$object->$method($value); | |
}; | |
public static function setAttributName($name){ | |
self::$attributName = $name; | |
return $this; | |
} | |
public static function getSetterCallable(){ | |
return self::$setterCallable; | |
} | |
public static function getIsCallable(){ | |
return self::$isCallable; | |
} | |
} | |
$attributMapper = array( | |
'id' => MapperCallableHelper::getSetterCallable(), | |
'name' => MapperCallableHelper::getSetterCallable(), | |
'size' => MapperCallableHelper::getSetterCallable(), | |
'mayor' => MapperCallableHelper::getSetterCallable(), | |
'enable' => MapperCallableHelper::getIsCallable(), | |
'country' => function (Mapper $mapper, $city, $value) { | |
/** @var Bouh\Demo\Entity\City $city */ | |
$city->countryIs($mapper->setObject(Bouh\Demo\Entity\Country::class, $value)); | |
} | |
); | |
$mapperConfigurationObject = new MapperConfigurationObject(Bouh\Demo\Entity\City::class); | |
foreach($attributMapper as $attribut => $callable){ | |
MapperCallableHelper::setAttributName($attribut); | |
$mapperConfigurationObject->deserializerHandlerForAttributeIs($attribut, $callable); | |
} | |
$mapperConfigurationObject->mapperConfigurationIs($mapperConfiguration); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment