From 5073d03454c9a4ef92ba93c26fa778a9c21fd607 Mon Sep 17 00:00:00 2001 From: Vadim Baryshev Date: Sun, 13 Apr 2014 13:15:46 +0400 Subject: [PATCH 1/2] Fix #1608 about Phalcon\Mvc\Router\Annotations Make it possible to define default route with `@Route('/')` annotation --- ext/mvc/router/annotations.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/mvc/router/annotations.c b/ext/mvc/router/annotations.c index e7b90950e38..52bdf901724 100644 --- a/ext/mvc/router/annotations.c +++ b/ext/mvc/router/annotations.c @@ -544,7 +544,11 @@ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){ PHALCON_INIT_VAR(uri); PHALCON_CONCAT_VV(uri, route_prefix, value); } else { - PHALCON_CPY_WRT(uri, route_prefix); + if (Z_TYPE_P(route_prefix) != IS_NULL) { + PHALCON_CPY_WRT(uri, route_prefix); + } else { + PHALCON_CPY_WRT(uri, value); + } } } else { PHALCON_INIT_NVAR(uri); From 412db0d17b1d865bb836e207b6a28e9ab95de321 Mon Sep 17 00:00:00 2001 From: Vadim Baryshev Date: Sun, 13 Apr 2014 13:38:05 +0400 Subject: [PATCH 2/2] Test case for #1608 --- unit-tests/RouterMvcAnnotationsTest.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/unit-tests/RouterMvcAnnotationsTest.php b/unit-tests/RouterMvcAnnotationsTest.php index b2db514d677..9beb62659bb 100644 --- a/unit-tests/RouterMvcAnnotationsTest.php +++ b/unit-tests/RouterMvcAnnotationsTest.php @@ -87,6 +87,19 @@ public function saveAction() } +class MainController +{ + + /** + * @Get("/") + */ + public function indexAction() + { + + } + +} + class RouterMvcAnnotationsTest extends PHPUnit_Framework_TestCase { public function _getDI() @@ -105,10 +118,11 @@ public function testRouterFullResources() $router->addResource('Robots'); $router->addResource('Products'); + $router->addResource('Main'); $router->handle(); - $this->assertEquals(count($router->getRoutes()), 7); + $this->assertEquals(count($router->getRoutes()), 8); $route = $router->getRouteByName('save-robot'); $this->assertTrue(is_object($route)); @@ -175,6 +189,13 @@ public function testRouterFullResources() 'action' => 'deleteRobot', 'params' => array('id' => '100') ), + array( + 'uri' => '/', + 'method' => 'GET', + 'controller' => 'Main', + 'action' => 'index', + 'params' => array() + ), ); foreach ($routes as $route) {