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

[jfw] Re: Container and use of an alias



Hang on, I tested it incorrectly. I used the wrong assertion (used assertEquals instead of assertSame). Using assertSame shows that they do not reference the same object.

I'll look into this.

On Tuesday, December 16, 2014 1:46:34 PM UTC-6, Don Gilbert wrote:
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.