当前位置: 首页>>代码示例>>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;未经允许,请勿转载。