【发布时间】:2017-02-23 15:51:08
【问题描述】:
我在 symfony 项目中构建捆绑包时遇到了意外行为。
我已经在 DependencyInjection 命名空间中构建了一个导出类,我只是这样做:
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter( 'auction.path', $config[ 'path' ] );
$container->setParameter( 'auction.miao', $config[ 'miao' ] );
$container->setParameter( 'auction.stock.pain', $config[ 'stock' ][ 'pain' ] );
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__.'/../Resources/config/')
);
}
}
理论上我应该简单地定义 3 个变量。如果我转储配置变量,我会得到以下输出:
Array
(
[path] => C:\progetti_symfony\repository-cms\src\AuctionBundle\DependencyInjection../web/images/tmp/
[miao] => C:\progetti_symfony\repository-cms\src\AuctionBundle\DependencyInjection../web/images/pmt/
)
其中嵌套的 stock.pain 部分(详见下一个 sn-p)被忽略。
然后我在同一个文件夹中有一个配置类,我在其中定义了这个包的配置(这里是我丢失指南针的地方):
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('auction');
$rootNode
->children()
->scalarNode('path')->defaultValue(__DIR__ . '../web/images/tmp/')->end()
->scalarNode('miao')->defaultValue(__DIR__ . '../web/images/pmt/')->end()
->arrayNode('stock')
->children()
->scalarNode('pain')->defaultValue(__DIR__ . '../web/images/mpt/')->end()
->end()
->end()
->end();
return $treeBuilder;
}
}
关于如何构建和访问此配置的任何建议?
【问题讨论】:
-
有什么问题?
标签: symfony