Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing plugin shortcuts entirely.

  • Loading branch information...
commit bdd8811924d3d0b4123bee2585439a1e0bbd7cf0 1 parent e57e8f3
Mark Story markstory authored
Showing with 2 additions and 189 deletions.
  1. +2 −71 cake/libs/router.php
  2. +0 −118 cake/tests/cases/libs/router.test.php
73 cake/libs/router.php
View
@@ -572,20 +572,14 @@ function __connectDefaultRoutes() {
foreach ($plugins as $key => $value) {
$plugins[$key] = Inflector::underscore($value);
}
- $pluginPiped = implode('|', $plugins);
- $match = array('plugin' => $pluginPiped);
- $shortPlugin = array('plugin' => $pluginPiped, 'routeClass' => 'PluginShortRoute');
+ $match = array('plugin' => implode('|', $plugins));
foreach ($this->__prefixes as $prefix) {
$params = array('prefix' => $prefix, $prefix => true);
$indexParams = $params + array('action' => 'index');
- $this->connect("/{$prefix}/:plugin", $indexParams, $shortPlugin);
- $this->connect("/{$prefix}/:plugin/:action/*", $params, $shortPlugin);
$this->connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
$this->connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
}
- $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);
}
@@ -925,7 +919,7 @@ function _handleNoRoute($url) {
$urlOut = array_filter(array($url['controller'], $url['action']));
- if (isset($url['plugin']) && $url['plugin'] != $url['controller']) {
+ if (isset($url['plugin'])) {
array_unshift($urlOut, $url['plugin']);
}
@@ -1550,10 +1544,6 @@ function match($url) {
* @access protected
*/
function _writeUrl($params) {
- if (isset($params['plugin'], $params['controller']) && $params['plugin'] === $params['controller']) {
- unset($params['controller']);
- }
-
if (isset($params['prefix'], $params['action'])) {
$params['action'] = str_replace($params['prefix'] . '_', '', $params['action']);
unset($params['prefix']);
@@ -1595,63 +1585,4 @@ function _writeUrl($params) {
return $out;
}
}
-
-/**
- * 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.
- *
- * @return void
- */
- function PluginShortRoute($template, $defaults = array(), $options = array()) {
- parent::CakeRoute($template, $defaults, $options);
- $plugins = App::objects('plugin');
- foreach ($plugins as $plugin) {
- $this->_plugins[Inflector::underscore($plugin)] = true;
- }
- }
-/**
- * Parses urls and creates the correct request parameter set.
- * If there is no controller available in the plugin with the same
- * name as the plugin, this route cannot pass.
- *
- * @param string $url Url string to parse.
- * @return mixed False on failure, or an array of request parameters
- */
- function parse($url) {
- $params = parent::parse($url);
- if (
- $params == false ||
- !isset($params['plugin']) ||
- (isset($params['plugin']) && !isset($this->_plugins[$params['plugin']]))
- ) {
- return false;
- }
- $pluginName = Inflector::camelize($params['plugin']);
- $controllerName = $pluginName . '.' . $pluginName;
- if (!App::import('Controller', $controllerName)) {
- return false;
- }
- if (!method_exists($pluginName . 'Controller', $params['action'])) {
- return false;
- }
- $params['controller'] = $params['plugin'];
- return $params;
- }
-
-}
?>
118 cake/tests/cases/libs/router.test.php
View
@@ -746,59 +746,6 @@ function testUrlGenerationPlugins() {
}
/**
- * test that plugin short cut routes behave properly. Parse and reverse route correctly.
- *
- * @return void
- */
- function testPluginShortcutRoutes() {
- App::build(array(
- 'plugins' => array(
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
- )
- ), true);
- App::objects('plugin', null, false);
- Configure::write('Routing.prefixes', array('admin'));
- Router::reload();
-
- $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
- $this->assertEqual($result, '/test_plugin', 'Plugin shortcut index action failed.');
-
- $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'view', 1));
- $this->assertEqual($result, '/test_plugin/view/1', 'Plugin shortcut with passed args failed.');
-
- $result = Router::url(array(
- 'plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'view',
- 1, 'sort' => 'title', 'dir' => 'asc'
- ));
- $this->assertEqual(
- $result, '/test_plugin/view/1/sort:title/dir:asc', 'Plugin shortcut with passed + named args failed.'
- );
-
- $result = Router::parse('/test_plugin');
- $this->assertEqual($result['plugin'], 'test_plugin');
- $this->assertEqual($result['controller'], 'test_plugin');
- $this->assertEqual($result['action'], 'index');
-
- $result = Router::parse('/test_plugin/add');
- $this->assertEqual($result['plugin'], 'test_plugin');
- $this->assertEqual($result['controller'], 'test_plugin');
- $this->assertEqual($result['action'], 'add');
-
- $result = Router::parse('/admin/test_plugin');
- $this->assertEqual($result['plugin'], 'test_plugin');
- $this->assertEqual($result['controller'], 'test_plugin');
- $this->assertEqual($result['action'], 'index');
- $this->assertEqual($result['prefix'], 'admin');
-
- $result = Router::parse('/admin/test_plugin/add/1');
- $this->assertEqual($result['plugin'], 'test_plugin');
- $this->assertEqual($result['controller'], 'test_plugin');
- $this->assertEqual($result['action'], 'add');
- $this->assertEqual($result['prefix'], 'admin');
- $this->assertEqual($result['pass'], array(1));
- }
-
-/**
* test that you can leave active plugin routes with plugin = null
*
* @return void
@@ -2469,69 +2416,4 @@ function testParse() {
}
}
-/**
- * Test case for PluginShortRoute
- *
- * @package cake.test.cases.libs
- */
-class PluginShortRouteTestCase extends CakeTestCase {
-/**
- * startTest method
- *
- * @access public
- * @return void
- */
- function startTest() {
- $this->_routing = Configure::read('Routing');
- Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
-
- App::build(array(
- 'plugins' => array(
- TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
- )
- ));
- App::objects('plugin', null, false);
- Router::reload();
- }
-
-/**
- * end the test and reset the environment
- *
- * @return void
- **/
- function endTest() {
- Configure::write('Routing', $this->_routing);
- App::build();
- }
-
-/**
- * test the parsing for plugin short routes.
- *
- * @return void
- */
- function testParsing() {
- $route =& new PluginShortRoute('/:plugin', array('action' => 'index'));
-
- $result = $route->parse('/non_existant_plugin');
- $this->assertFalse($result, 'Route matched when it should fail.');
-
- $result = $route->parse('/test_plugin');
- $this->assertEqual($result['plugin'], 'test_plugin');
- $this->assertEqual($result['controller'], 'test_plugin');
- $this->assertEqual($result['action'], 'index');
-
- $route =& new PluginShortRoute('/:plugin/:action/*');
-
- $result = $route->parse('/test_plugin/add');
- $this->assertEqual($result['plugin'], 'test_plugin');
- $this->assertEqual($result['controller'], 'test_plugin');
- $this->assertEqual($result['action'], 'add');
-
- $result = $route->parse('/test_plugin/add/1');
- $this->assertEqual($result['plugin'], 'test_plugin');
- $this->assertEqual($result['controller'], 'test_plugin');
- $this->assertEqual($result['action'], 'add');
- $this->assertEqual($result['_args_'], '1', 'Passed args were wrong.');
- }
-}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.