久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='3DueN'></tfoot>

    <small id='3DueN'></small><noframes id='3DueN'>

    <i id='3DueN'><tr id='3DueN'><dt id='3DueN'><q id='3DueN'><span id='3DueN'><b id='3DueN'><form id='3DueN'><ins id='3DueN'></ins><ul id='3DueN'></ul><sub id='3DueN'></sub></form><legend id='3DueN'></legend><bdo id='3DueN'><pre id='3DueN'><center id='3DueN'></center></pre></bdo></b><th id='3DueN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3DueN'><tfoot id='3DueN'></tfoot><dl id='3DueN'><fieldset id='3DueN'></fieldset></dl></div>
  • <legend id='3DueN'><style id='3DueN'><dir id='3DueN'><q id='3DueN'></q></dir></style></legend>

      • <bdo id='3DueN'></bdo><ul id='3DueN'></ul>
      1. 如果我沒有/無法使用 DI 注入服務,我如何直接從

        How do I get a service from the container directly, if I didn#39;t/couldn#39;t inject the service using DI?(如果我沒有/無法使用 DI 注入服務,我如何直接從容器中獲取服務?)

            <bdo id='k5fbp'></bdo><ul id='k5fbp'></ul>

            1. <tfoot id='k5fbp'></tfoot>
            2. <small id='k5fbp'></small><noframes id='k5fbp'>

                <tbody id='k5fbp'></tbody>

              <legend id='k5fbp'><style id='k5fbp'><dir id='k5fbp'><q id='k5fbp'></q></dir></style></legend>

              1. <i id='k5fbp'><tr id='k5fbp'><dt id='k5fbp'><q id='k5fbp'><span id='k5fbp'><b id='k5fbp'><form id='k5fbp'><ins id='k5fbp'></ins><ul id='k5fbp'></ul><sub id='k5fbp'></sub></form><legend id='k5fbp'></legend><bdo id='k5fbp'><pre id='k5fbp'><center id='k5fbp'></center></pre></bdo></b><th id='k5fbp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='k5fbp'><tfoot id='k5fbp'></tfoot><dl id='k5fbp'><fieldset id='k5fbp'></fieldset></dl></div>
                • 本文介紹了如果我沒有/無法使用 DI 注入服務,我如何直接從容器中獲取服務?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一部分代碼,我通過依賴注入注入了兩個服務 $checker$paginator.它完美地工作:

                  I have a part of code where I'm injecting two services $checker and $paginator by dependency injection. It works perfectly:

                  public function index(Request $request, Paginator $paginator, Checker $checker)
                      {
                          $result = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
                          $partialResult = $paginator->getPartial($result, 0, 3);
                          $checker->isValid('A');
                          var_dump("test");
                          die;
                      }
                  

                  services.yaml文件的配置下面:

                     paginator:
                          public: true
                          class: 'AppHelperPaginator'
                  
                      checker:
                          public: true
                          class: 'AppHelperChecker'
                          arguments:
                           $paginator: '@paginator'
                  

                  但由于某些原因我想通過方法注入服務:

                  But I'd like to inject for some reasons service by method:

                  $checker = $this->container->get('checker');
                  

                  但它不起作用.在以前的 Symfony 版本中,像 3.4 那樣.

                  But it doesn't work. In previous versions Symfony like 3.4 it used to.

                  我收到一個錯誤:

                  未找到服務checker":事件雖然它存在于應用程序的容器中,但AppControllerDefaultController"中的容器是一個較小的服務定位器,它只知道http_kernel"、parameter_bag"、request_stack"、路由器"、會話"和樹枝"服務.嘗試改用依賴注入.

                  Service "checker" not found: event though it exists in the app's container, the container inside "AppControllerDefaultController" is a smaller service locator that only knows about the "http_kernel", "parameter_bag", "request_stack", "router", "session", and "twig" services. Try using dependency injection instead.

                  我該如何解決這個問題?

                  How should I solve this?

                  推薦答案

                  你需要添加你的依賴項 服務定位器可以找到它們.

                  You need to add your dependencies so the service locator can find them.

                  將方法 getSubscribedServices() 添加到您的控制器類:

                  Add a method getSubscribedServices() to your controller class:

                  public static function getSubscribedServices()
                  {
                      return array_merge(
                          parent::getSubscribedServices(),
                          [
                              'checker' => Checker::class,
                          ]
                      );
                  }
                  

                  如果你的控制器類擴展了 AbstractController 你可以簡單地做:

                  If your controller class extends AbstractController you can simply do:

                  $this->get('checker');
                  

                  如果您想在其他類型的類中執行此操作(例如不擴展AbstractController 的服務),那么您需要聲明您的服務實現了ServiceSubscriberInterface.

                  If you want to do it in another type of class (e.g. a service that doesn't extend AbstractController), then you need to declare that your service implements the ServiceSubscriberInterface.

                  use SymfonyContractsServiceServiceSubscriberInterface;
                  use PsrContainerContainerInterface;
                  
                  class FooService implements ServiceSubscriberInterface {
                  
                      public function __construct(ContainerInterface $locator)
                      {
                          $this->locator = $locator;
                      }
                  
                      public static function getSubscribedServices() { /* same as before */ }
                  
                      public function get($service)
                      {
                          return $this->locator->get($service);
                      }
                  }
                  

                  ...并且您可以像之前在控制器中那樣做同樣的事情.

                  ... and you would be able to do the same than you in the controller earlier.

                  這篇關于如果我沒有/無法使用 DI 注入服務,我如何直接從容器中獲取服務?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                  <small id='Z5ES9'></small><noframes id='Z5ES9'>

                    <bdo id='Z5ES9'></bdo><ul id='Z5ES9'></ul>
                      <tbody id='Z5ES9'></tbody>
                      <tfoot id='Z5ES9'></tfoot>
                        1. <i id='Z5ES9'><tr id='Z5ES9'><dt id='Z5ES9'><q id='Z5ES9'><span id='Z5ES9'><b id='Z5ES9'><form id='Z5ES9'><ins id='Z5ES9'></ins><ul id='Z5ES9'></ul><sub id='Z5ES9'></sub></form><legend id='Z5ES9'></legend><bdo id='Z5ES9'><pre id='Z5ES9'><center id='Z5ES9'></center></pre></bdo></b><th id='Z5ES9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Z5ES9'><tfoot id='Z5ES9'></tfoot><dl id='Z5ES9'><fieldset id='Z5ES9'></fieldset></dl></div>
                          <legend id='Z5ES9'><style id='Z5ES9'><dir id='Z5ES9'><q id='Z5ES9'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 天天干天天干 | 国产亚洲人成a在线v网站 | 看a网站 | 亚洲一区二区三区在线 | 91av视频 | 午夜a区 | 狠狠天天| 久久久久久免费毛片精品 | 成人国产精品视频 | 欧日韩不卡在线视频 | 欧美日韩精品在线一区 | 成人一区av | 午夜无码国产理论在线 | 国产精品毛片一区二区在线看 | 日韩中文字幕一区 | 色吊丝2 | 欧美日本久久 | 国产精品久久国产精品久久 | 日韩av视屏| 久久精品亚洲欧美日韩精品中文字幕 | 国产精品久久久久久久久久久久久 | 午夜天堂精品久久久久 | 欧美电影免费网站 | 精品美女| 国产一区二区视频在线 | 欧美成人精品一区二区男人看 | 一区二区三区四区电影视频在线观看 | 国产亚洲区 | 久久国产精品精品国产色婷婷 | 美日韩一区二区 | 国产亚洲成av人片在线观看桃 | 成人小视频在线免费观看 | 午夜视频在线观看网址 | 国产免费自拍 | 黄网在线观看 | 欧美一级视频 | 日本小视频网站 | 日韩在线视频免费观看 | 亚洲免费精品 | 91秦先生艺校小琴 | 中文字幕亚洲欧美日韩在线不卡 |