我有一个由许多捆绑包组成的Symfony2(2.8.1)应用程序。我想要一个"关于"页面,显示每个捆绑包的版本。为了做到这一点,我尝试使用这样的参数数组:
revision:
'bundle1':
version: 1.0.0
build: 42
'bundle2':
version: 1.2.0
build: 4242
等等。如果我把所有东西都放在一个YAML文件中,它就可以工作了。相反,我希望每个捆绑包都定义其修订版。类似于:bundle1:的参数文件
revision:
'bundle1':
version: 1.0.0
build: 42
和bundle2:的参数文件
revision:
'bundle2':
version: 1.2.0
build: 4242
如果我这样做,修订数组只填充最后一个包含的yaml文件的值。有没有一种方法可以将条目"添加"到不同yaml文件中定义的参数数组中?BRStefano
我改变了方法并解决了问题。我只是在每个bundle的config文件夹中创建一个Yaml文件,而不是将修订信息添加到配置中。然后,我将yaml文件的内容加载到一个数组中,以便在about页面中使用。
代码类似于:
# first place to check is app config folder
$kernel_root=$this->get('kernel')->getRootDir();
$toLocate[]=$kernel_root.'/config';
# then get config folder for each active bundle
$kernel = $this->get('kernel');
$configDirectories=$this->getParameter('kernel.bundles');
foreach ($configDirectories as $bundleName => $configDirectory) {
$toLocate[]= $kernel->locateResource('@'.$bundleName).'Resources/config';
}
# now get array of revision files
$locator = new FileLocator($toLocate);
$yamlRevFiles = $locator->locate('revision.yml', null, false);
# and finally create array of date read from revision files
$revs=array();
foreach ($yamlRevFiles as $yamlRevFile) {
$revs[]=Yaml::parse($yamlRevFile);
}