简体   繁体   English

Slim3 DI容器访问差异

[英]Slim3 DI container access diferrence

$app->get('......',....)
$container=$this->getContainer();

Is there any difference between the following? 以下内容之间有什么区别吗? Pimple docs uses the former while slim examples the latter. Pimple文档使用前者,而苗条的示例使用后者。 Is any of the two considered more formal in PSR terms? 在PSR术语中,这两者是否被认为是更正式的?

    $server=$container['App\Model\Server'];

    $server=$container->get('App\Model\Server');

Slims Container implements the Interop/ContainerInterface , whereas Pimple does not. Slims Container实现了Interop / ContainerInterface ,而Pimple没有实现。 The Interop/ContainerInterface requires the container to have two methods: get() and has() . Interop / ContainerInterface要求容器具有两个方法: get()has() get() throws an exception ( NotFoundException ) when an entry is not found. 找不到条目时, get()会引发异常( NotFoundException )。 With plain Pimple you only get a notice. 使用普通的丘疹,您只会收到通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM