[TYPO3-mvc] URIBuilder rewrite
Xavier Perseguers
typo3 at perseguers.ch
Tue Sep 1 19:40:11 CEST 2009
Hi @all Extbase/Fluid enthusiasts,
It would be great to have a feedback on this, in order for Bastian and me to know what is your opinion.
Thanks.
Xavier Perseguers wrote:
> 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
http://xavier.perseguers.ch/en
One contribution a day keeps the fork away
More information about the TYPO3-project-typo3v4mvc
mailing list