コード例 #1
0
 /**
  * {@inheritdoc}
  *
  * @deprecated since version 2.4, to be removed in 3.0.
  */
 public function getIndicesForChoices(array $choices)
 {
     trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
     if (!$this->valuePath) {
         return parent::getIndicesForChoices($choices);
     }
     // Use the value path to compare the choices
     $choices = $this->fixChoices($choices);
     $indices = array();
     foreach ($choices as $i => $givenChoice) {
         // Ignore non-readable choices
         if (!is_object($givenChoice) && !is_array($givenChoice)) {
             continue;
         }
         $givenValue = (string) $this->propertyAccessor->getValue($givenChoice, $this->valuePath);
         foreach ($this->values as $j => $value) {
             if ($value === $givenValue) {
                 $indices[$i] = $j;
                 unset($choices[$i]);
                 if (0 === count($choices)) {
                     break 2;
                 }
             }
         }
     }
     return $indices;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  *
  * @deprecated Deprecated since version 2.4, to be removed in 3.0.
  */
 public function getIndicesForChoices(array $choices)
 {
     if (!$this->valuePath) {
         return parent::getIndicesForChoices($choices);
     }
     // Use the value path to compare the choices
     $choices = $this->fixChoices($choices);
     $indices = array();
     foreach ($choices as $i => $givenChoice) {
         // Ignore non-readable choices
         if (!is_object($givenChoice) && !is_array($givenChoice)) {
             continue;
         }
         $givenValue = (string) $this->propertyAccessor->getValue($givenChoice, $this->valuePath);
         foreach ($this->values as $j => $value) {
             if ($value === $givenValue) {
                 $indices[$i] = $j;
                 unset($choices[$i]);
                 if (0 === count($choices)) {
                     break 2;
                 }
             }
         }
     }
     return $indices;
 }
コード例 #3
0
ファイル: MenuChoiceList.php プロジェクト: geoffreytran/zym
 /**
  * Returns the indices corresponding to the given entities.
  *
  * @param array $entities
  *
  * @return array
  *
  * @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
  */
 public function getIndicesForChoices(array $entities)
 {
     if (!$this->loaded) {
         // Optimize performance for single-field identifiers. We already
         // know that the IDs are used as indices
         // Attention: This optimization does not check choices for existence
         if ($this->idAsIndex) {
             $indices = array();
             foreach ($entities as $entity) {
                 if ($entity instanceof $this->class) {
                     // Make sure to convert to the right format
                     $indices[] = $this->fixIndex(current($this->getIdentifierValues($entity)));
                 }
             }
             return $indices;
         }
         $this->load();
     }
     return parent::getIndicesForChoices($entities);
 }