[Form] Fixed choice list hashing in DoctrineType

This commit is contained in:
Bernhard Schussek 2012-07-13 14:48:51 +02:00
parent 2bf4d6cff4
commit 2ca753bc68

View File

@ -68,17 +68,40 @@ abstract class DoctrineType extends AbstractType
$choiceList = function (Options $options) use ($registry, &$choiceListCache, &$time) { $choiceList = function (Options $options) use ($registry, &$choiceListCache, &$time) {
$manager = $registry->getManager($options['em']); $manager = $registry->getManager($options['em']);
$choiceHashes = is_array($options['choices']) // Support for closures
? array_map('spl_object_hash', $options['choices']) $propertyHash = is_object($options['property'])
: $options['choices']; ? spl_object_hash($options['property'])
: $options['property'];
$choiceHashes = $options['choices'];
// Support for recursive arrays
if (is_array($choiceHashes)) {
// A second parameter ($key) is passed, so we cannot use
// spl_object_hash() directly (which strictly requires
// one parameter)
array_walk_recursive($choiceHashes, function ($value) {
return spl_object_hash($value);
});
}
// Support for custom loaders (with query builders)
$loaderHash = is_object($options['loader'])
? spl_object_hash($options['loader'])
: $options['loader'];
// Support for closures
$groupByHash = is_object($options['group_by'])
? spl_object_hash($options['group_by'])
: $options['group_by'];
$hash = md5(json_encode(array( $hash = md5(json_encode(array(
spl_object_hash($manager), spl_object_hash($manager),
$options['class'], $options['class'],
$options['property'], $propertyHash,
$options['loader'], $loaderHash,
$choiceHashes, $choiceHashes,
$options['group_by'] $groupByHash
))); )));
if (!isset($choiceListCache[$hash])) { if (!isset($choiceListCache[$hash])) {