我目前正在重構一個Silex\Application
,它的增長量比最初預期的要大。作爲這項工作的一部分,我將服務定義從源移動到services.yml中,而不是調用Symfony\Component\DependencyInjection\ContainerBuilder
。代碼如下所示:使用Symfony Component DependencyInjection配置具有路徑的Silex應用程序
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load(__DIR__ . '/services.yml');
考慮下面的代碼行,這是創造的一部分Doctrine\ORM\EntityManager
:
Setup::createAnnotationMetadataConfiguration(array("src/Project/Entity"), true);
它看起來像這樣在我services.yml:
services:
doctrine_config:
class: Doctrine\ORM\Configuration
factory_class: Doctrine\ORM\Tools\Setup
factory_method: createAnnotationMetadataConfiguration
arguments:
- [src/Project/Entity]
- true
最後,我的問題。我想將一個鍵和值傳遞給容器構建器,我可以像參數一樣訪問容器構建器,例如而不是[src/Project/Entity]
作爲Doctrine-Setup的第一個參數我想要這樣做:[%ROOT_PATH%/src/Project/Entity]
,其中%ROOT_PATH%
被添加到ContainerBuilder,有點像$container->???('ROOT_PATH', dirname(__DIR__))
。
我在文檔中找不到這樣的東西。我將通讀ContainerBuilder.php來了解我是否能找到某些東西,但我不確定這些術語,例如在我的場景中是否爲%OOT_PATH%
是變量,定義,別名...