本文整理汇总了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);
}
示例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;
}
示例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'];
}
示例4: testToArrayKey
/**
* @dataProvider toArrayKeyProvider
*/
public function testToArrayKey($in, $out)
{
$this->assertSame($out, FormUtil::toArrayKey($in));
}
示例5: transform
public function transform($value)
{
return FormUtil::toArrayKey($value);
}