簡體   English   中英

Slim3 DI容器訪問差異

[英]Slim3 DI container access diferrence

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

以下內容之間有什么區別嗎? Pimple文檔使用前者,而苗條的示例使用后者。 在PSR術語中,這兩者是否被認為是更正式的?

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

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

Slims Container實現了Interop / ContainerInterface ,而Pimple沒有實現。 Interop / ContainerInterface要求容器具有兩個方法: get()has() 找不到條目時, get()會引發異常( NotFoundException )。 使用普通的丘疹,您只會收到通知。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM