EXTMVC:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / View / Helper / TX_EXTMVC_View_Helper_URIHelper.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 framework. *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * A URI/Link Helper
25 *
26 * @version $Id:$
27 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
28 */
29 class TX_EXTMVC_View_Helper_URIHelper extends TX_EXTMVC_View_Helper_AbstractHelper {
30
31 /**
32 * @var TX_EXTMVC_Web_Routing_RouterInterface
33 */
34 protected $router;
35
36 /**
37 * Injects the Router
38 *
39 * @param TX_EXTMVC_Web_Routing_RouterInterface $router
40 * @return void
41 */
42 public function injectRouter(TX_EXTMVC_Web_Routing_RouterInterface $router) {
43 $this->router = $router;
44 }
45
46 /**
47 * Creates a link by making use of the Routers reverse routing mechanism.
48 *
49 * @param string $label Inner HTML of the generated link. Label is htmlspecialchared by default
50 * @param string $actionName Name of the action to be called
51 * @param array $arguments Additional arguments
52 * @param string $controllerName Name of the target controller. If not set, current controller is used
53 * @param string $extensionKey Name of the target extension. If not set, current extension is used
54 * @param string $subextensionKey Name of the target subextension. If not set, current subextension is used
55 * @param array $options Further options
56 * @return string the HTML code for the generated link
57 * @see UIRFor()
58 */
59 public function linkTo($label, $actionName, $arguments = array(), $controllerName = NULL, $extensionKey = NULL) {
60 $link = '<a href="' . $this->URIFor($actionName, $arguments, $controllerName, $extensionKey) . '">' . htmlspecialchars($label) . '</a>';
61 return $link;
62 }
63
64 /**
65 * Creates an URI by making use of the Routers reverse routing mechanism.
66 *
67 * @param string $actionName Name of the action to be called
68 * @param array $arguments Additional arguments
69 * @param string $controllerName Name of the target controller. If not set, current controller is used
70 * @param string $extensionKey Name of the target extension. If not set, current extension is used
71 * @param array $options Further options
72 * @return string the HTML code for the generated link
73 */
74 public function URIFor($actionName, $arguments = array(), $controllerName = NULL, $extensionKey = NULL) {
75 $routeValues = $arguments;
76 $routeValues['@action'] = $actionName;
77 $routeValues['@controller'] = ($controllerName === NULL) ? $this->request->getControllerName() : $controllerName;
78 $routeValues['@extension'] = ($extensionKey === NULL) ? $this->request->getControllerExtensionKey() : $extensionKey;
79
80 $URIString = $this->router->resolve($routeValues);
81 return $URIString;
82 }
83 }
84
85 ?>