1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4: * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * Redistributions of files must retain the above copyright notice.
8: *
9: * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
10: * @link http://cakephp.org CakePHP(tm) Project
11: * @since CakePHP(tm) v 1.3
12: * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
13: */
14:
15: App::uses('CakeRoute', 'Routing/Route');
16:
17: /**
18: * Plugin short route, that copies the plugin param to the controller parameters
19: * It is used for supporting /:plugin routes.
20: *
21: * @package Cake.Routing.Route
22: */
23: class PluginShortRoute extends CakeRoute {
24:
25: /**
26: * Parses a string url into an array. If a plugin key is found, it will be copied to the
27: * controller parameter
28: *
29: * @param string $url The url to parse
30: * @return mixed false on failure, or an array of request parameters
31: */
32: public function parse($url) {
33: $params = parent::parse($url);
34: if (!$params) {
35: return false;
36: }
37: $params['controller'] = $params['plugin'];
38: return $params;
39: }
40:
41: /**
42: * Reverse route plugin shortcut urls. If the plugin and controller
43: * are not the same the match is an auto fail.
44: *
45: * @param array $url Array of parameters to convert to a string.
46: * @return mixed either false or a string url.
47: */
48: public function match($url) {
49: if (isset($url['controller']) && isset($url['plugin']) && $url['plugin'] != $url['controller']) {
50: return false;
51: }
52: $this->defaults['controller'] = $url['controller'];
53: $result = parent::match($url);
54: unset($this->defaults['controller']);
55: return $result;
56: }
57: }