1. Чтобы бы вы сделали иначе
2. Какие ошибки
3. Что доработать
4. Удобство в пользовании
основной класс neusRouter
Спойлер (Отобразить)
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- class neusRouter
- {
- protected $_config = NULL;
- protected $_route = NULL;
- public function __construct()
- {
- //
- }
- public function route($url)
- {
- if($this->_config === null)
- throw new Exception('config no found');
- if($url[0] === 'index' || $url[0] === '')
- {
- $this->_route = $this->_config->getConfig();
- $this->_params = $this->_config->getParams();
- 'route' => $this->_route,
- 'vars' => $this->_vars,
- 'params' => $this->_params
- );
- }
- $config = $this->_config;
- $childs = $config->getChilds();
- foreach($url as $u)
- {
- $found = false;
- {
- $found = true;
- $config = $childs[$u];
- $childs = $config->getChilds();
- }
- else
- {
- foreach($childs as $key=>$value)
- {
- $preg = $value->getPreg($key);
- {
- foreach($preg['vars'] as $key=>$var)
- $vars[$var] = $matches[$key+1][0];
- $config = $value;
- $childs = $config->getChilds();
- $found = true;
- break;
- }
- }
- }
- if($found === false)
- throw new Exception('Not found');
- }
- $this->_route = $config->getConfig();
- $this->_vars = $vars;
- $this->_params = $config->getParams();
- 'route' => $this->_route,
- 'vars' => $this->_vars,
- 'params' => $this->_params
- );
- }
- public function getRoutes()
- {
- $this->_route;
- }
- public function getRoute($key)
- {
- return $this->_route[$key];
- else
- return false;
- }
- public function getVars()
- {
- $this->_vars;
- }
- public function getVar($key)
- {
- return $this->_vars[$key];
- else
- return false;
- }
- public function getParams()
- {
- $this->_params;
- }
- public function getParam($key)
- {
- return $this->_params[$key];
- else
- return false;
- }
- public function setConfig(neusRouterConfigInterface $config)
- {
- $this->_config = $config;
- }
- public function createConfig($route)
- {
- return ($this->_config = new neusRouterConfig($route));
- }
- }