В принципе, я хотел бы разрешить произвольное (но не пустое) число пар ключ-значение в моей конфигурации под billings
node, что определяет ассоциативный массив.
У меня это в моей Configurator.php
(часть):
->arrayNode('billings')
->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')
->end()
->end()
И затем, в моем config.yml
:
my_bundle:
billings:
monthly : Monthly
bimonthly : Bimonthly
Однако вывод $config
:
class MyBundleExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container,
new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs);
$container->setParameter('my_bundle.billings', $config['billings']);
var_dump($config);
die();
}
}
... я получаю индекс массива по номерам, а не ассоциативный:
'billings' =>
array (size=2)
0 => string 'Monthly' (length=7)
1 => string 'Bimonthly' (length=9)
Из любопытства (и если это может помочь), я пытаюсь ввести этот массив в качестве параметра службы (аннотации из этого великого пакета: JMSDiExtraBundle):
class BillingType extends \Symfony\Component\Form\AbstractType
{
/**
* @var array
*/
private $billingChoices;
/**
* @InjectParams({"billingChoices" = @Inject("%billings%")})
*
* @param array $billingChoices
*/
public function __construct(array $billingChoices)
{
$this->billingChoices = $billingChoices;
}
}