基本上我想在我的配置中允许任意(但不是空)数量的键值对billings
,在节点下,即定义一个关联数组。
我的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;
}
}