GithubHelp home page GithubHelp logo

zendframework / zend-servicemanager-di Goto Github PK

View Code? Open in Web Editor NEW
6.0 15.0 11.0 1.48 MB

zend-di <-> zend-servicemanager integration

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%

zend-servicemanager-di's Introduction

zend-servicemanager-di's People

Contributors

koopzington avatar madkatze avatar michalbundyra avatar weierophinney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zend-servicemanager-di's Issues

Uncaught TypeError: Argument 2 passed to Zend\ServiceManager\Di\DiServiceFactory::get()

I'm using Zend\ServiceManager\Di\DiAbstractServiceFactory to create objects and it causes the fatal error:
Fatal error: Uncaught TypeError: Argument 2 passed to Zend\ServiceManager\Di\DiServiceFactory::get() must be of the type array, null given.

The issue related to incorrect implementation of \Zend\ServiceManager\Di\DiServiceFactory::get. As default parameter it uses an empty array but other methods can call it with null.

do not work

Example application: https://github.com/bupy7/zf3-sm-di

zend-servicemanager-di is not work.

Download application and run the application: composer serve

Error list:

  1. Create new instance of controller via DI: http://localhost::8080 - ERROR
  2. Create new instance of service via DI: http://localhost:8080/testservice - ERROR
  3. Invalid class name for Container Interop. You can see my fix in Application/Module:19-21 line
  4. Zend\ServiceManager\Di\DiAbstractServiceFactory was initialized double. Screenshot var_dump https://drive.google.com/open?id=0B9GZdWo-fVk0SkxGemo3Z1dzMUk . Code in Application/Module.

In ZF2 it all worked.

DiAbstractServiceFactory Recursion

  • I was not able to find an open or closed issue matching what I'm seeing.
  • This is not a question. (Questions should be asked on chat (Signup here) or our forums.)

The Zend\ServiceManager\Di\DiAbstractServiceFactory when used as an abstract factory is causing recursion.

The issue is caused by Zend\ServiceManager\ServiceManager::has() function implementation and Zend\ServiceManager\Di\DiAbstractServiceFactoryFactory: :__invoke() function which is using DiAbstractServiceFactory::USE_SL_BEFORE_DI and Zend\ServiceManager\Di\DiServiceFactory: :get() method which is sending the object initialization request back to the Zend\ServiceManager\ServiceManager and as a result creating the recursion.

During object initialization by ServiceManager via DiAbstractServiceFactory the DiServiceFactory::get() method checks whether it should call ServiceManager (Service Locator) first by the following code (line 126) and therefore sends the object initialization request back to the ServiceManager because both conditions for the if statement are correct in this situation.

// Allow this di service to get dependencies from the service locator BEFORE trying DI.
if ($this->useContainer === self::USE_SL_BEFORE_DI && $this->container->has($name)) {    
     return $this->container->get($name);
 }

As the object initialization request is sent or pushed back to the ServiceManager and the ServiceManager will forward the request again to DiAbstractServiceFactory therefore creating the recursion (sending the request back and forth) and the end result is system memory exhausted.

Code to reproduce the issue

Please just use Zend\ServiceManager\Di\DiAbstractServiceFactory as an abstract factory
and then use ServiceManager to get/initialize an object. This object should not have any other factory class defined in the config. The only factory which should initialize this object should be Zend\ServiceManager\Di\DiAbstractServiceFactory.

Expected results

No Recursion.

Actual results

Recursion

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.