1. <small id='wC9Rr'></small><noframes id='wC9Rr'>

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

      1. <legend id='wC9Rr'><style id='wC9Rr'><dir id='wC9Rr'><q id='wC9Rr'></q></dir></style></legend>

        <tfoot id='wC9Rr'></tfoot>

        <i id='wC9Rr'><tr id='wC9Rr'><dt id='wC9Rr'><q id='wC9Rr'><span id='wC9Rr'><b id='wC9Rr'><form id='wC9Rr'><ins id='wC9Rr'></ins><ul id='wC9Rr'></ul><sub id='wC9Rr'></sub></form><legend id='wC9Rr'></legend><bdo id='wC9Rr'><pre id='wC9Rr'><center id='wC9Rr'></center></pre></bdo></b><th id='wC9Rr'></th></span></q></dt></tr></i><div id='wC9Rr'><tfoot id='wC9Rr'></tfoot><dl id='wC9Rr'><fieldset id='wC9Rr'></fieldset></dl></div>
      2. 已弃用:在功能系统中检索服务定位器 - ZF2

        时间:2023-10-02
      3. <legend id='MhGZo'><style id='MhGZo'><dir id='MhGZo'><q id='MhGZo'></q></dir></style></legend>

          <tfoot id='MhGZo'></tfoot>

            <tbody id='MhGZo'></tbody>

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

                <bdo id='MhGZo'></bdo><ul id='MhGZo'></ul>
              • <i id='MhGZo'><tr id='MhGZo'><dt id='MhGZo'><q id='MhGZo'><span id='MhGZo'><b id='MhGZo'><form id='MhGZo'><ins id='MhGZo'></ins><ul id='MhGZo'></ul><sub id='MhGZo'></sub></form><legend id='MhGZo'></legend><bdo id='MhGZo'><pre id='MhGZo'><center id='MhGZo'></center></pre></bdo></b><th id='MhGZo'></th></span></q></dt></tr></i><div id='MhGZo'><tfoot id='MhGZo'></tfoot><dl id='MhGZo'><fieldset id='MhGZo'></fieldset></dl></div>
                • 本文介绍了已弃用:在功能系统中检索服务定位器 - ZF2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在开发一个 ZF2 系统,它运行良好,但是在我在其他计算机上克隆存储库后,出现了这个已弃用的错误:

                  I'm developing a ZF2 system and it was working very well, but after I clone the repository in other computer this deprecated error has appeared:

                  您正在从 ModuleControllerController 类中检索服务定位器.请注意,ServiceLocatorAwareInterface 已弃用,将在 3.0 版中与 ServiceLocatorAwareInitializer 一起删除.您需要更新您的类以在创建时接受所有依赖项,通过构造函数参数或设置器,并使用工厂来执行注入.在第 258 行的/home/path/project/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php 中

                  You are retrieving the service locator from within the class ModuleControllerController. Please be aware that ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along with the ServiceLocatorAwareInitializer. You will need to update your class to accept all dependencies at creation, either via constructor arguments or setters, and use a factory to perform the injections. in /home/path/project/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php on line 258

                  composer.json:

                  The composer.json:

                  "require": {
                      "php": ">=5.5",
                      "ext-curl": "*",
                      "ext-json": "*",
                      "ext-mbstring": "*",
                      "zendframework/zendframework": "~2.5",
                      "doctrine/doctrine-orm-module": "0.*",
                      "hounddog/doctrine-data-fixture-module": "0.0.*",
                      "imagine/Imagine": "~0.5.0"
                  

                  在我的控制器中检索服务时出现错误(扩展 ZendMvcControllerAbstractActionController):

                  The error appears when I retrieve the service in my controllers (extending ZendMvcControllerAbstractActionController):

                  $this->getServiceLocator()->get("ModuleServiceService");
                  

                  在 Zend 内核中 ZendMvcControllerAbstractController 是这样的:

                  In the Zend core at ZendMvcControllerAbstractController is like this:

                  public function getServiceLocator()
                  {
                      trigger_error(sprintf(
                          'You are retrieving the service locator from within the class %s. Please be aware that '
                          . 'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along '
                          . 'with the ServiceLocatorAwareInitializer. You will need to update your class to accept '
                          . 'all dependencies at creation, either via constructor arguments or setters, and use '
                          . 'a factory to perform the injections.',
                          get_class($this)
                      ), E_USER_DEPRECATED);
                  
                      return $this->serviceLocator;
                  }
                  

                  以前只有这个:

                  public function getServiceLocator()
                  {
                      return $this->serviceLocator;
                  }
                  

                  我什么都试过了,有人知道我该怎么做吗?

                  I've tried everything, someone know what I've to do?

                  推荐答案

                  您无需执行任何操作,还没有.当您升级到 ZF3 时,您将不得不更改控制器类接收其依赖项的方式.

                  You don't have to do anything, yet. When you upgrade to ZF3, then you will have to change how your controller class receives its dependencies.

                  ZF2 支持两种依赖注入模式:通过服务定位器和通过构造函数.ZF3 删除了按服务位置"并需要按构造函数".所有这一切都有效地改变了依赖关系的解决方式,将解决方案从及时"转移到构建时".

                  ZF2 supports two dependency injection patterns: by service locator and by constructor. ZF3 removes "by service location" and requires "by constructor". All this does, effectively, is change how dependencies resolve, moving the resolution from "just in time" to "at construction".

                  您不能从任何地方获得服务,而是在施工处接收它们.按照以下几行更新您的代码:

                  Instead of being able to get a service from anywhere, you instead receive them at construction. Update your code along the following lines:

                  namespace ModuleController;
                  
                  class Controller {
                      public function __construct(ModuleServiceService $service) {
                          $this->service = $service;
                      }
                  }
                  

                  在类的方法中需要$this->service 的地方使用它.

                  Use $this->service where you need it in the class's methods.

                  然后使用控制器工厂来创建您的控制器,如下所示:

                  Then use a controller factory to create your controller, like so:

                  function ($controllers) { 
                      $services = $controllers->getServiceLocator();
                      return new ModuleControllerController($services->get('ModuleServiceService')); 
                  } 
                  

                  在问题 5168 和 这篇博文 讨论了为什么使用服务定位器的服务注入是一种反模式.

                  The change is discussed in Issue 5168, and this blog post discusses why service injection with a service locator is an anti-pattern.

                  这篇关于已弃用:在功能系统中检索服务定位器 - ZF2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:需要一个解释如何使用 PHPUnit 的站点 下一篇:在 Zend_Form 中,如何避免 Zend_Validate_Email 产生多个

                  相关文章

                  最新文章

                  1. <legend id='3kko5'><style id='3kko5'><dir id='3kko5'><q id='3kko5'></q></dir></style></legend>

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

                        <bdo id='3kko5'></bdo><ul id='3kko5'></ul>

                    1. <i id='3kko5'><tr id='3kko5'><dt id='3kko5'><q id='3kko5'><span id='3kko5'><b id='3kko5'><form id='3kko5'><ins id='3kko5'></ins><ul id='3kko5'></ul><sub id='3kko5'></sub></form><legend id='3kko5'></legend><bdo id='3kko5'><pre id='3kko5'><center id='3kko5'></center></pre></bdo></b><th id='3kko5'></th></span></q></dt></tr></i><div id='3kko5'><tfoot id='3kko5'></tfoot><dl id='3kko5'><fieldset id='3kko5'></fieldset></dl></div>

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