/** * @return null */ public function setUp() { $route = 'welcome'; $ns = 'TestFuel\\Functional\\Action\\Welcome'; MvcRouteManager::addRoute('welcome', $ns); $this->masterKey = $route; $this->handler = new MvcRouteHandler($route); }
/** * @param string $key * @return string | false */ public function getNamespace($key) { return MvcRouteManager::getNamespace($key); }
/** * 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; }
/** * @param string $key main route key * @param array $data * @return null */ protected function loadConfiguration($masterKey, array $masterConfig = null, array $aliases = null) { $namespace = MvcRouteManager::getNamespace($masterKey); if (false === $namespace) { $err = "namespace not found -({$masterKey}) make sure route map "; $err .= "is loaded into the MvcRouteManager"; throw new LogicException($err); } $this->setMasterKey($masterKey); if (null === $masterConfig) { $masterConfig = array(); } $masterConfig['namespace'] = $namespace; /* * merge the default config array so that we can use a completed * master array without forcing the developer to all items. This * way we can aliases into master and pick up default values */ $masterConfig = $this->merge($this->getDefaultConfig(), $masterConfig); $this->setMasterDetail($this->createRouteDetail($masterConfig)); if (empty($aliases)) { return $this; } if ($aliases === array_values($aliases)) { $err = "second param must be an associative array -(key=>config)"; throw new InvalidArgumentException($err); } $map = array(); foreach ($aliases as $key => $data) { if (!is_string($key)) { $err = 'alias config invalid: route key must be a string'; throw new InvalidArgumentException($err); } if ($masterKey === $key) { continue; } if (is_array($data)) { if (empty($data)) { $data['namespace'] = $namespace; $detail = $this->createRouteDetail($data); } else { if (isset($data['is-inherit']) && false === $data['is-inherit']) { $data['namespace'] = $namespace; $detail = $this->createRouteDetail($data); } else { $config = $this->merge($masterConfig, $data); if (null === $config) { $err = "invalid alias config for -({$key}) could not "; $err .= "inherit from master config"; throw new InvalidArgumentException($err); } $detail = $this->createRouteDetail($config); } } $map[$key] = $detail; } else { if (is_string($data)) { if ($masterKey === $data || array_key_exists($data, $aliases)) { $map[$key] = $data; } else { $err = "alias pointer to other detail failed: "; $err .= "-({$data}) is not an alias or master route key"; throw new InvalidArgumentException($err); } } else { if ($data instanceof MvcRouteDetailInterface) { $map[$key] = $data; } else { if (empty($data)) { $map[$key] = $masterKey; } } } } } $this->aliasMap = $map; return $this; }
/** * @return null */ public function testGetRouteThatExistsButNotLoader() { $key = 'my-route'; $key2 = 'alias-a'; $key3 = 'alias-b'; $key4 = 'alias-c'; $ns = 'TestFuel\\Functional\\Action\\TestRouteManager'; MvcRouteManager::addRoute($key, $ns); MvcRouteManager::addRoute($key2, $ns); MvcRouteManager::addRoute($key3, $ns); MvcRouteManager::addRoute($key4, $ns); $this->assertEquals(array(), MvcRouteManager::getAllCache()); $detail = MvcRouteManager::getRouteDetail($key); $this->assertInstanceOf('Appfuel\\Kernel\\Mvc\\MvcRouteDetail', $detail); $this->assertSame($detail, MvcRouteManager::getRouteDetail($key2)); $this->assertSame($detail, MvcRouteManager::getRouteDetail($key3)); $this->assertSame($detail, MvcRouteManager::getRouteDetail($key4)); }
/** * @param string $key * @return MvcRouteDetailInterface */ public function createRouteDetail($key) { return MvcRouteManager::getRouteDetail($key); }