當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FormUtil::toArrayKey方法代碼示例

本文整理匯總了PHP中Symfony\Component\Form\Util\FormUtil::toArrayKey方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormUtil::toArrayKey方法的具體用法?PHP FormUtil::toArrayKey怎麽用?PHP FormUtil::toArrayKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Form\Util\FormUtil的用法示例。


在下文中一共展示了FormUtil::toArrayKey方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: transform

 public function transform($value)
 {
     if (null !== $value && !is_scalar($value)) {
         throw new UnexpectedTypeException($value, 'scalar');
     }
     return FormUtil::toArrayKey($value);
 }
開發者ID:artz20,項目名稱:Tv-shows-zone,代碼行數:7,代碼來源:ScalarToChoiceTransformer.php

示例2: transform

 /**
  * Transforms a single choice to a format appropriate for the nested
  * checkboxes/radio buttons.
  *
  * The result is an array with the options as keys and true/false as values,
  * depending on whether a given option is selected. If this field is rendered
  * as select tag, the value is not modified.
  *
  * @param  mixed $value  An array if "multiple" is set to true, a scalar
  *                       value otherwise.
  *
  * @return mixed         An array
  *
  * @throws UnexpectedTypeException if the given value is not scalar
  * @throws TransformationFailedException if the choices can not be retrieved
  */
 public function transform($value)
 {
     if (!is_scalar($value) && null !== $value) {
         throw new UnexpectedTypeException($value, 'scalar');
     }
     try {
         $choices = $this->choiceList->getChoices();
     } catch (\Exception $e) {
         throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
     }
     $value = FormUtil::toArrayKey($value);
     foreach (array_keys($choices) as $key) {
         $choices[$key] = $key === $value;
     }
     return $choices;
 }
開發者ID:robertowest,項目名稱:CuteFlow-V4,代碼行數:32,代碼來源:ScalarToBooleanChoicesTransformer.php

示例3: isChoiceSelected

    public function isChoiceSelected($choice)
    {
        $choice = FormUtil::toArrayKey($choice);

        // The value should already have been converted by value transformers,
        // otherwise we had to do the conversion on every call of this method
        if (is_array($this->vars['value'])) {
            return false !== array_search($choice, $this->vars['value'], true);
        }

        return $choice === $this->vars['value'];
    }
開發者ID:nacef,項目名稱:symfony,代碼行數:12,代碼來源:FormView.php

示例4: testToArrayKey

 /**
  * @dataProvider toArrayKeyProvider
  */
 public function testToArrayKey($in, $out)
 {
     $this->assertSame($out, FormUtil::toArrayKey($in));
 }
開發者ID:usefulthink,項目名稱:symfony,代碼行數:7,代碼來源:FormUtilTest.php

示例5: transform

 public function transform($value)
 {
     return FormUtil::toArrayKey($value);
 }
開發者ID:nacef,項目名稱:symfony,代碼行數:4,代碼來源:ScalarToChoiceTransformer.php


注:本文中的Symfony\Component\Form\Util\FormUtil::toArrayKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。