翻译优化
wj2015
3年前
修改理由:
此投稿已在 3年前 合并。
内容修改:
Old | New | Differences |
---|---|---|
2 | 2 | |
3 | 3 | ## 开发环境 |
4 | 4 | |
5 | PHP-DI | |
5 | PHP-DI 的容器已预先配置好,开发环境可以“即插即用”。您可以像这样简单地使用它: | |
6 | 6 | |
7 | 7 | ```php |
8 | 8 | $container = new Container(); | … | … |
31 | 31 | |
32 | 32 | 阅读 [关于性能](performances.md) 了解更多。 |
33 | 33 | |
34 | ## 轻量 | |
34 | ## 轻量级容器 | |
35 | 35 | |
36 | 如果要 | |
36 | 如果要将 PHP-DI 容器当做简单容器 (没有自动装配或注解)使用, 则可以禁用其所有的额外功能。 | |
37 | 37 | |
38 | 38 | ```php |
39 | 39 | $builder = new \DI\ContainerBuilder(); | … | … |
51 | 51 | 如果要一次使用多个容器,例如要在ZF2或Symfony 2中使用PHP-DI,则可以 |
52 | 52 | 使用 [Acclimate](https://github.com/jeremeamia/acclimate)之类的工具。 |
53 | 53 | |
54 | 您只需要告知 | |
54 | 您只需要告知 PHP-DI 复合容器, 否则 PHP-DI 不会感知到 Symfony 的容器条目。 | |
55 | 55 | |
56 | Acclimate | |
56 | Acclimate 示例: | |
57 | 57 | |
58 | 58 | ```php |
59 | 59 | $container = new Acclimate\Container\CompositeContainer(); |
60 | 60 | |
61 | // | |
61 | // 添加 Symfony 容器 | |
62 | 62 | $container->addContainer($acclimate->adaptContainer($symfonyContainer)); |
63 | 63 | |
64 | 64 | // 配置 PHP-DI 容器 |
65 | 65 | $builder = new \DI\ContainerBuilder(); |
66 | 66 | $builder->wrapContainer($container); |
67 | 67 | |
68 | // | |
68 | // 添加 PHP-DI 容器 | |
69 | 69 | $phpdiContainer = $builder->build(); |
70 | 70 | $container->addContainer($phpdiContainer); |
71 | 71 | |
72 | // | |
72 | // 准备好了,用吧! | |
73 | 73 | $foo = $container->get('foo'); |
74 | 74 | ``` |
75 | 75 |