/** * @param \Kendo\Routing\RoutingResult $result * * @return bool */ protected function filter(RoutingResult $result) { $any = $result->get('any'); // admin dashboard if (empty($any)) { $result->setVars(['controller' => 'Platform\\Core\\Controller\\Admin\\DashboardController', 'action' => 'index']); return true; } $parts = explode('/', $any); if (count($parts) < 2) { return false; } $bundle = array_shift($parts); $module = array_shift($parts); $lastControl = null; $actionName = null; // the last path is action if (!empty($parts)) { $actionName = array_pop($parts); } else { $actionName = $module; } if (!empty($parts)) { $lastControl = array_pop($parts); } if (empty($lastControl)) { $lastControl = $module; } if (empty($actionName)) { $actionName = $lastControl; } $join = [$bundle, $module, 'Controller', 'Admin']; if (!empty($parts)) { foreach ($parts as $part) { $join[] = $part; } } $join[] = $lastControl . '-controller'; $controllerName = '\\' . implode('\\', array_map("_inflect", $join)); if (class_exists($controllerName)) { $result->addVars(['controller' => $controllerName, 'action' => $actionName]); return true; } return false; }
/** * @param $uri * @param null $host * @param RoutingResult $result * * @return array|bool */ public function resolve($uri, $host = null, RoutingResult $result) { $params = []; if ($host && $this->host) { if (!preg_match($this->hostCompiledExpression, $host, $matches)) { return false; } foreach ($matches as $key => $value) { if (is_int($key)) { continue; } // Set the value for all matched keys $params[$key] = $value; } } if ($uri && $this->uri) { if (!preg_match($this->uriCompiledExpression, $uri, $matches)) { return false; } foreach ($matches as $key => $value) { if (is_int($key)) { continue; } // Set the value for all matched keys $params[$key] = $value; } } foreach ($this->defaults as $key => $value) { if (!isset($params[$key]) or $params[$key] === '') { // Set default values for any key that was not matched $params[$key] = $value; } } $result->setVars($params); if (false == $this->filter($result)) { return false; } if (app()->routing()->resolveChildren($this->delegate, $uri, $host, $result)) { return true; } if (app()->routing()->resolveChildren($this->name, $uri, $host, $result)) { return true; } return true; }