Skip to content

Commit

Permalink
[Form] Fixed choice list hashing in DoctrineType
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed Jul 13, 2012
1 parent 2bf4d6c commit 2ca753b
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Expand Up @@ -68,17 +68,40 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
$choiceList = function (Options $options) use ($registry, &$choiceListCache, &$time) {
$manager = $registry->getManager($options['em']);

$choiceHashes = is_array($options['choices'])
? array_map('spl_object_hash', $options['choices'])
: $options['choices'];
// Support for closures
$propertyHash = is_object($options['property'])
? 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(
spl_object_hash($manager),
$options['class'],
$options['property'],
$options['loader'],
$propertyHash,
$loaderHash,
$choiceHashes,
$options['group_by']
$groupByHash
)));

if (!isset($choiceListCache[$hash])) {
Expand Down

0 comments on commit 2ca753b

Please sign in to comment.