/** * {@inheritdoc} */ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null) { $hash = self::generateHash(array($loader, $value), 'fromLoader'); if (!isset($this->lists[$hash])) { $this->lists[$hash] = $this->decoratedFactory->createListFromLoader($loader, $value); } return $this->lists[$hash]; }
private function createChoiceList(array $options) { if (null !== $options['choice_loader']) { return $this->choiceListFactory->createListFromLoader($options['choice_loader'], $options['choice_value']); } // Harden against NULL values (like in EntityType and ModelType) $choices = null !== $options['choices'] ? $options['choices'] : array(); return $this->choiceListFactory->createListFromChoices($choices, $options['choice_value']); }
/** * {@inheritdoc} * * @param ChoiceLoaderInterface $loader The choice loader * @param null|callable|string|PropertyPath $value The callable or path for * generating the choice values * * @return ChoiceListInterface The choice list */ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null) { if (is_string($value)) { $value = new PropertyPath($value); } if ($value instanceof PropertyPath) { $accessor = $this->propertyAccessor; $value = function ($choice) use($accessor, $value) { return $accessor->getValue($choice, $value); }; } return $this->decoratedFactory->createListFromLoader($loader, $value); }
/** * {@inheritdoc} * * @param ChoiceLoaderInterface $loader The choice loader * @param null|callable|string|PropertyPath $value The callable or path for * generating the choice values * * @return ChoiceListInterface The choice list */ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null) { if (is_string($value) && !is_callable($value)) { $value = new PropertyPath($value); } if ($value instanceof PropertyPath) { $accessor = $this->propertyAccessor; $value = function ($choice) use($accessor, $value) { // The callable may be invoked with a non-object/array value // when such values are passed to // ChoiceListInterface::getValuesForChoices(). Handle this case // so that the call to getValue() doesn't break. if (is_object($choice) || is_array($choice)) { return $accessor->getValue($choice, $value); } }; } return $this->decoratedFactory->createListFromLoader($loader, $value); }
/** * {@inheritdoc} * * @param ChoiceLoaderInterface $loader The choice loader * @param null|callable|string|PropertyPath $value The callable or path for * generating the choice values * * @return ChoiceListInterface The choice list */ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null) { if (is_string($value) && !is_callable($value)) { $value = new PropertyPath($value); } elseif (is_string($value) && is_callable($value)) { @trigger_error('Passing callable strings is deprecated since version 3.1 and PropertyAccessDecorator will treat them as property paths in 4.0. You should use a "\\Closure" instead.', E_USER_DEPRECATED); } if ($value instanceof PropertyPath) { $accessor = $this->propertyAccessor; $value = function ($choice) use($accessor, $value) { // The callable may be invoked with a non-object/array value // when such values are passed to // ChoiceListInterface::getValuesForChoices(). Handle this case // so that the call to getValue() doesn't break. if (is_object($choice) || is_array($choice)) { return $accessor->getValue($choice, $value); } }; } return $this->decoratedFactory->createListFromLoader($loader, $value); }