/** * A mapping of route keys to action controller namespaces is kept to * simplify the uri's generated and used by the framework. This is not * optional and must used as part of the framework. In the uri the first * component in the path or the name 'routekey' in the query string is * the key for the route. When no key is found the route key '' is used. * Here we will initialize the route list into the KernelRegistry * * @param null|string|array $routes * @return null */ public function initRouteMap($routes = null) { if (null === $routes || is_string($routes)) { $map = $this->getData('routes', $routes); } else { if (!empty($routes) && is_array($routes)) { $map = $routes; } } $max = count($map); MvcRouteManager::setRouteMap($map); $result = "route map intiailized with {$max} routes"; self::$status['mvc route manager:routes'] = $result; return $this; }
/** * @return null */ public function testLoadRouteMapWithExistingRoutes() { $list1 = array('routeA' => 'my\\a\\namespace', 'routeB' => 'my\\b\\namespace', 'routeC' => 'my\\c\\namespace'); $this->assertEquals(array(), MvcRouteManager::getRouteMap()); $this->assertNull(MvcRouteManager::setRouteMap($list1)); $this->assertEquals($list1, MvcRouteManager::getRouteMap()); $list2 = array('routeD' => 'my\\d\\namespace', 'routeE' => 'my\\e\\namespace', 'routeF' => 'my\\f\\namespace'); $expected = array_merge($list1, $list2); /* this will replace the whole map */ $this->assertNull(MvcRouteManager::loadRouteMap($list2)); $this->assertEquals($expected, MvcRouteManager::getRouteMap()); }