[TYPO3-mvc] URIBuilder rewrite
Xavier Perseguers
typo3 at perseguers.ch
Tue Sep 1 10:16:42 CEST 2009
Hi Bastian,
>> please add a "return $this" at the end of method reset().
>> This will allow us to write $this->uriBuilder->reset()->uriFor()
>
> I disagree (sorry). I think it's fine to have a fluent interface for
> "stupid" setters. But having reset() there seems to be out of place. How
> are others thinking about this?
It is not a must-have but a should-have as stated in the bug/feature report.
Problem is that when you deal with generating ExtJS code for instance,
you have to generate lots of URL in order for AJAX to work. And having
chaining there allows this for instance:
$jsCode = '
var url1 = "' . $this->uriBuilder->reset()->uriFor('index') . '";
var url2 = "' . $this->uriBuilder->reset()->uriFor('otherAction') . '";
var url3 = "' .
$this->uriBuilder->reset()->uriFor('yetAnotherAction') . '";
';
Otherwise you have to write this:
$this->uriBuilder->reset();
$jsCode = 'var url1 = "' . $this->uriBuilder->uriFor('index') . '";';
$this->uriBuilder->reset();
$jsCode .= 'var url2 = "' . $this->uriBuilder->uriFor('otherAction') . '";';
$this->uriBuilder->reset();
$jsCode .= 'var url3 = "' .
$this->uriBuilder->uriFor('yetAnotherAction') . '";';
Once again, this is just an example and it works well as you did without
chaining but chaining reset() would allow much more flexibility.
> BTW: I found out, that method chaining is hard to test cause not only
> you have to mock the uriBuilder but all its setters in order to avoid
> fatal errors in your unit tests..
Yes, but as I read your code first I did not see the comment that stated
that chaining was there and thought "Hey, great idea to allow chaining
there". Thus it's worth the effort ;-)
>> Did you tried BlogExample with your changes? Seems that the "reset"
>> problem is there too...
>
> What problem exactly? Do you have the latest versions of TYPO3 core,
> extbase, fluid & blog_example?
Yesterday as I tested there was a bug with wrongly generated links (of
course I updated all those exts) but this morning I saw that at any
point of time Fluid had been updated. I guess that was the problem and
I'm pretty sure it now works :-)
--
Xavier Perseguers
MVC ExtJS Leader
http://forge.typo3.org/projects/show/extension-mvc_extjs
More information about the TYPO3-project-typo3v4mvc
mailing list