Browse files

enable PluginDot for routeClass parameter

  • Loading branch information...
1 parent 99b798f commit 0cae19a14e089f49285d600098c5238bb1941f12 @rchavik rchavik committed Sep 12, 2012
View
7 lib/Cake/Routing/Router.php
@@ -304,7 +304,12 @@ public static function connect($route, $defaults = array(), $options = array())
}
$routeClass = self::$_routeClass;
if (isset($options['routeClass'])) {
- $routeClass = self::_validateRouteClass($options['routeClass']);
+ if (strpos($options['routeClass'], '.') === false) {
+ $routeClass = $options['routeClass'];
+ } else {
+ list($plugin, $routeClass) = pluginSplit($options['routeClass'], true);
+ }
+ $routeClass = self::_validateRouteClass($routeClass);
unset($options['routeClass']);
}
if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) {
View
20 lib/Cake/Test/Case/Routing/RouterTest.php
@@ -2283,6 +2283,26 @@ public function testUsingCustomRouteClass() {
}
/**
+ * test using custom route class in PluginDot notation
+ */
+ public function testUsingCustomRouteClassPluginDotSyntax() {
+ App::build(array(
+ 'Plugin' => array(
+ CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
+ )
+ ));
+ CakePlugin::load('TestPlugin');
+ App::uses('TestRoute', 'TestPlugin.Routing/Route');
+ $routes = Router::connect(
+ '/:slug',
+ array('controller' => 'posts', 'action' => 'view'),
+ array('routeClass' => 'TestPlugin.TestRoute', 'slug' => '[a-z_-]+')
+ );
+ $this->assertInstanceOf('TestRoute', $routes[0]);
+ CakePlugin::unload('TestPlugin');
+ }
+
+/**
* test that route classes must extend CakeRoute
*
* @expectedException RouterException
View
7 lib/Cake/Test/test_app/Plugin/TestPlugin/Lib/Routing/Route/TestRoute.php
@@ -0,0 +1,7 @@
+<?php
+
+App::uses('CakeRoute', 'Routing/Route');
+
+class TestRoute extends CakeRoute {
+
+}

0 comments on commit 0cae19a

Please sign in to comment.