[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[jfw] Re: Container and use of an alias




The issue I experience is that I set a shared object to the container, when you retrieve it with the long key it will set an instance to the instances array with that long key, but if you try then to get that "shared" object with the alias key you will get a newly created one and set to the instances array with the alias key.

Am Dienstag, 16. Dezember 2014 20:46:34 UTC+1 schrieb Don Gilbert:
I've added tests to prove this and created a PR: https://github.com/joomla-framework/di/pull/10

Sven, I think the issue you are experiencing is that the callable you are passing ( [$this, 'getResponse'] ) returns a different object. If you register your key with a callback, that exact callback is used when fetching the item from the container, not the value returned by the callback. So you are getting, each time you get it from the container, the value returned by your $this->getResponse() method (as in, that method is called every time you request $c->get('jresponse');

If you want to use the value, simply register it like this:

$c->set('MyApp\\Interfaces\\App\\AppResponseInterface', $this->getResponse(), true, true)
  ->alias('jresponse', 'MyApp\\Interfaces\\App\AppResponseInterface');

--
Framework source code: https://github.com/joomla-framework
Visit http://developer.joomla.org for more information about developing with Joomla!
---
You received this message because you are subscribed to the Google Groups "Joomla! Framework Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-framework+unsubscribe AT googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-framework.