Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding doc blocks to PluginShortRoute. Adding PluginShortRoute into R…

…outer.
  • Loading branch information...
commit a18d1be4c3ce8ac1184956322e6dbf8fc009f663 1 parent f605454
@markstory markstory authored
Showing with 23 additions and 2 deletions.
  1. +23 −2 cake/libs/router.php
View
25 cake/libs/router.php
@@ -568,6 +568,9 @@ function __connectDefaultRoutes() {
$this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
$this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
}
+ $shortPlugin = array_merge($match, array('routeClass' => 'PluginShortRoute'));
+ $this->connect('/:plugin', array('action' => 'index'), $shortPlugin);
+ $this->connect('/:plugin/:action/*', array(), $shortPlugin);
$this->connect('/:plugin/:controller', array('action' => 'index'), $match);
$this->connect('/:plugin/:controller/:action/*', array(), $match);
}
@@ -1578,7 +1581,21 @@ function _writeUrl($params) {
}
}
+/**
+ * PluginShortRoute is a specialized route class to handle routes
+ * where the controller and plugin are named the same. It allows you
+ * to omit the controller key from the template and the defaults.
+ * When a url is parsed, this class will attempt to import a controller
+ * with the same name. If that succeeds the request array will be modified.
+ *
+ * @package cake.libs
+ */
class PluginShortRoute extends CakeRoute {
+/**
+ * A cache for all the plugins in the application
+ *
+ * @var string
+ */
var $_plugins = array();
/**
* Constructor Sets up the plugin sets.
@@ -1594,7 +1611,6 @@ function PluginShortRoute($template, $defaults = array(), $options = array()) {
}
/**
* Parses urls and creates the correct request parameter set.
- * Plugin short cut routes have the same plugin and controller keys.
* If there is no controller available in the plugin with the same
* name as the plugin, this route cannot pass.
*
@@ -1603,7 +1619,11 @@ function PluginShortRoute($template, $defaults = array(), $options = array()) {
*/
function parse($url) {
$params = parent::parse($url);
- if (!isset($params['plugin']) || (isset($params['plugin']) && !isset($this->_plugins[$params['plugin']]))) {
+ if (
+ $params == false ||
+ !isset($params['plugin']) ||
+ (isset($params['plugin']) && !isset($this->_plugins[$params['plugin']]))
+ ) {
return false;
}
$pluginName = Inflector::camelize($params['plugin']);
@@ -1614,5 +1634,6 @@ function parse($url) {
$params['controller'] = $params['plugin'];
return $params;
}
+
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.