/** * * * @param $ControllerKey * @param $Parts * @return bool * @throws Exception * @throws GdnDispatcherControllerFoundException */ protected function findController($ControllerKey, $Parts) { $Controller = val($ControllerKey, $Parts, null); $Controller = ucfirst(strtolower($Controller)); $Application = val($ControllerKey - 1, $Parts, null); // Check for a file extension on the controller. list($Controller, $this->_DeliveryMethod) = $this->_splitDeliveryMethod($Controller, false); // If we're loading from a fully qualified path, prioritize this app's library if (!is_null($Application)) { Gdn_Autoloader::priority(Gdn_Autoloader::CONTEXT_APPLICATION, $Application, Gdn_Autoloader::MAP_CONTROLLER, Gdn_Autoloader::PRIORITY_TYPE_RESTRICT, Gdn_Autoloader::PRIORITY_ONCE); } $ControllerName = $Controller . 'Controller'; $ControllerPath = Gdn_Autoloader::lookup($ControllerName, array('MapType' => null)); try { // If the lookup succeeded, good to go if (class_exists($ControllerName, false)) { throw new GdnDispatcherControllerFoundException(); } } catch (GdnDispatcherControllerFoundException $Ex) { // This was a guess search with no specified application. Look up // the application folder from the controller path. if (is_null($Application)) { if (!$ControllerPath && class_exists($ControllerName, false)) { $Reflect = new ReflectionClass($ControllerName); $Found = false; do { $ControllerPath = $Reflect->getFilename(); $Found = (bool) preg_match('`\\/controllers\\/`i', $ControllerPath); if (!$Found) { $Reflect = $Reflect->getParentClass(); } } while (!$Found && $Reflect); if (!$Found) { return false; } } if ($ControllerPath) { $InterimPath = explode('/controllers/', $ControllerPath); array_pop($InterimPath); // Get rid of the end. Useless; $InterimPath = explode('/', trim(array_pop($InterimPath))); $Application = array_pop($InterimPath); $AddonType = array_pop($InterimPath); switch ($AddonType) { case 'plugins': if (!in_array($Application, Gdn::pluginManager()->enabledPluginFolders())) { return false; } $Application = 'plugins/' . $Application; break; case 'applications': if (!in_array($Application, $this->enabledApplicationFolders())) { return false; } break; default: return false; } } else { return false; } } // If we need to autoload the class, do it here if (!class_exists($ControllerName, false)) { Gdn_Autoloader::priority(Gdn_Autoloader::CONTEXT_APPLICATION, $Application, Gdn_Autoloader::MAP_CONTROLLER, Gdn_Autoloader::PRIORITY_TYPE_PREFER, Gdn_Autoloader::PRIORITY_PERSIST); require_once $ControllerPath; } $this->ControllerName = $Controller; $this->_ApplicationFolder = is_null($Application) ? '' : $Application; $Length = sizeof($Parts); if ($Length > $ControllerKey + 1) { list($this->ControllerMethod, $this->_DeliveryMethod) = $this->_splitDeliveryMethod($Parts[$ControllerKey + 1], false); } if ($Length > $ControllerKey + 2) { for ($i = $ControllerKey + 2; $i < $Length; ++$i) { if ($Parts[$i] != '') { $this->_ControllerMethodArgs[] = $Parts[$i]; } } } throw $Ex; } return false; }