Removed Closure support from group_by (PropertyPath strings only)

This commit is contained in:
Eric Clemmons 2011-10-25 08:55:31 -07:00
parent 037933a2ec
commit e6554d6d45
2 changed files with 7 additions and 43 deletions

View File

@ -160,17 +160,13 @@ class EntityChoiceList extends ArrayChoiceList
$grouped = array();
foreach ($entities as $entity) {
if ($groupBy instanceof \Closure) {
// Get group name from Closure
$group = $groupBy($entity);
} else {
// Get group name from property path
try {
$path = new PropertyPath($groupBy);
$group = (string) $path->getValue($entity);
} catch (UnexpectedTypeException $e) {
// PropertyPath cannot traverse entity
}
// Get group name from property path
try {
$path = new PropertyPath($groupBy);
$group = (string) $path->getValue($entity);
} catch (UnexpectedTypeException $e) {
// PropertyPath cannot traverse entity
$group = null;
}
if (empty($group)) {

View File

@ -150,36 +150,4 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
'4' => 'Boo!'
), $choiceList->getChoices('choices'));
}
public function testGroupBySupportsClosure()
{
$item1 = new ItemGroupEntity(1, 'Foo', 'Group1');
$item2 = new ItemGroupEntity(2, 'Bar', 'Group2');
$item3 = new ItemGroupEntity(3, 'Baz', null);
$this->em->persist($item1);
$this->em->persist($item2);
$this->em->persist($item3);
$choiceList = new EntityChoiceList(
$this->em,
self::ITEM_GROUP_CLASS,
'name',
null,
array(
$item1,
$item2,
$item3,
),
function($entity) {
return $entity->group_name;
}
);
$this->assertEquals(array(
'Group1' => array(1 => 'Foo'),
'Group2' => array(2 => 'Bar'),
'3' => 'Baz'
), $choiceList->getChoices('choices'));
}
}