[TYPO3-mvc] URIBuilder rewrite
Bastian Waidelich
bastian at typo3.org
Tue Aug 11 17:08:58 CEST 2009
Hello @ all you busy bees ;)
I need your opinions regarding the rewrite of the infamous URIBuilder
(see http://forge.typo3.org/issues/show/3981 and
http://forge.typo3.org/issues/show/4030)
We realized, that the methods URIFor() and typolinkURI() need more and
more parameters in order to support the most important features of the
typolink-monster. As a side-effect Extbase's URIBuilder gets out of
synch with FLOW3's URIBuilder and maintainability sucks cause you have
to change the signatures every time you add new settings. Apart from
that, the current URIBuilder can't really be extended which will hurt at
the latest when we need a special TYPO3v5 version of it..
So here my suggestions for a rewrite:
- rename "URIBuilder" to "UriBuilder" - that's got nothing to do with
the above, but we should do it anyways ;)
- rename "URIFor" to "uriFor" - see above
- rename "typolinkURI" to "render()" (Extbase), add "render()" (FLOW3)
and last but not least: extract most of the method arguments to
protected fields with setters.
Here my suggestions for the new methods:
Extbase & FLOW3:
setArguments(array)
setSection(string)
setAbsoluteUri(boolean)
only FLOW3:
setFormat(string) // will probably come to Extbase too
only Extbase:
setAddQueryString(boolean)
setAddQueryStringExcludeArguments(array)
setLinkAccessRestrictedPages(boolean)
setTargetPageUid(integer)
setTargetPageType(integer)
setNoCache(boolean)
setUseCacheHash(boolean)
All of the setters would return the uriBuilder to support method
chaining like:
$uriBuilder
->setArguments(array('foo' => 'bar'))
->setSection('baz')
->setFormat('xml')
and for each setter there's a corresponding getter of course
And finally there would be:
FLOW3:
uriFor($actionName = NULL, $controllerArguments = array(),
$controllerName = NULL, $packageKey = NULL, $subpackageKey = NULL);
Extbase:
uriFor($actionName = NULL, $controllerArguments = array(),
$controllerName = NULL, $extensionName = NULL, $pluginName = NULL);
Obviously, most of you won't have to deal with that anyways, cause
you'll be using Fluid to generate URIs/links most of the time. If you
create an URI from PHP code this could look like this in Extbase:
$uriBuilder
->setTargetPageUid(123)
->setArguments(array('foo' => 'bar'))
->uriFor('someAction', array('some' => 'argument'))
that would return:
index.php?id=123&foo=bar&tx_yourext_yourplugin[action]=someAction&tx_yourext_yourplugin[controller]=currentController&tx_yourext_yourplugin[some]=argument
To create general links, you'd have
$uriBuilder
->setTargetPageUid(123)
->setArguments(array('tt_news' => array('article' => 321))
->render()
returns:
index.php?id=123&tt_news[article]=321
Now my questions:
- Do you agree at all?
- Do you have suggestions for better method names?
"setAddQueryStringExcludeArguments" is weird ;)
- Are there important features missing? E.g. do we need to support
typolinks "addQueryString.method" setting or an equivalent for
pi_linkTP_keepPIvars?
- Anything else?
looking forward to your feedback
Bastian
BTW: a nice bonus of this implementation is, that you can use the same
instance to generate multiple links:
$uriBuilder
->setTargetPageUid(123)
->setTargetPageType(321);
foreach($posts as $post) {
$uris[] = $uriBuilder->uriFor('show', array('post' => $post));
}
More information about the TYPO3-project-typo3v4mvc
mailing list