public function testCompareChoicesByIdentityByDefault()
 {
     $callback = function ($choice) {
         return $choice->value;
     };
     $obj1 = (object) array('value' => 'value1');
     $obj2 = (object) array('value' => 'value2');
     $choiceList = new ArrayChoiceList(array($obj1, $obj2), $callback);
     $this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => $obj2)));
     $this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => (object) array('value' => 'value2'))));
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function getValuesForChoices(array $choices)
 {
     $choices = array_map(array(__CLASS__, 'toArrayKey'), $choices);
     if ($this->useChoicesAsValues) {
         // If the choices are identical to the values, we can just return
         // them to improve performance a little bit
         return array_map('strval', array_intersect($choices, $this->choices));
     }
     return parent::getValuesForChoices($choices);
 }