<tfoot id='cIoiy'></tfoot>

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

        <i id='cIoiy'><tr id='cIoiy'><dt id='cIoiy'><q id='cIoiy'><span id='cIoiy'><b id='cIoiy'><form id='cIoiy'><ins id='cIoiy'></ins><ul id='cIoiy'></ul><sub id='cIoiy'></sub></form><legend id='cIoiy'></legend><bdo id='cIoiy'><pre id='cIoiy'><center id='cIoiy'></center></pre></bdo></b><th id='cIoiy'></th></span></q></dt></tr></i><div id='cIoiy'><tfoot id='cIoiy'></tfoot><dl id='cIoiy'><fieldset id='cIoiy'></fieldset></dl></div>
        <legend id='cIoiy'><style id='cIoiy'><dir id='cIoiy'><q id='cIoiy'></q></dir></style></legend>
          <bdo id='cIoiy'></bdo><ul id='cIoiy'></ul>

      1. 已弃用:在功能系统中检索服务定位器 - ZF2

        Deprecated: Retrieve service locator in functional system - ZF2(已弃用:在功能系统中检索服务定位器 - ZF2)

            <tbody id='7B9hp'></tbody>

        • <small id='7B9hp'></small><noframes id='7B9hp'>

          <legend id='7B9hp'><style id='7B9hp'><dir id='7B9hp'><q id='7B9hp'></q></dir></style></legend>

              1. <i id='7B9hp'><tr id='7B9hp'><dt id='7B9hp'><q id='7B9hp'><span id='7B9hp'><b id='7B9hp'><form id='7B9hp'><ins id='7B9hp'></ins><ul id='7B9hp'></ul><sub id='7B9hp'></sub></form><legend id='7B9hp'></legend><bdo id='7B9hp'><pre id='7B9hp'><center id='7B9hp'></center></pre></bdo></b><th id='7B9hp'></th></span></q></dt></tr></i><div id='7B9hp'><tfoot id='7B9hp'></tfoot><dl id='7B9hp'><fieldset id='7B9hp'></fieldset></dl></div>
                  <bdo id='7B9hp'></bdo><ul id='7B9hp'></ul>
                  <tfoot id='7B9hp'></tfoot>
                  本文介绍了已弃用:在功能系统中检索服务定位器 - 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                      <tfoot id='ZDcd7'></tfoot>

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

                          <tbody id='ZDcd7'></tbody>
                        1. <small id='ZDcd7'></small><noframes id='ZDcd7'>

                        2. <i id='ZDcd7'><tr id='ZDcd7'><dt id='ZDcd7'><q id='ZDcd7'><span id='ZDcd7'><b id='ZDcd7'><form id='ZDcd7'><ins id='ZDcd7'></ins><ul id='ZDcd7'></ul><sub id='ZDcd7'></sub></form><legend id='ZDcd7'></legend><bdo id='ZDcd7'><pre id='ZDcd7'><center id='ZDcd7'></center></pre></bdo></b><th id='ZDcd7'></th></span></q></dt></tr></i><div id='ZDcd7'><tfoot id='ZDcd7'></tfoot><dl id='ZDcd7'><fieldset id='ZDcd7'></fieldset></dl></div>
                          • <legend id='ZDcd7'><style id='ZDcd7'><dir id='ZDcd7'><q id='ZDcd7'></q></dir></style></legend>