protected function FindController($ControllerKey, $Parts) { $Application = GetValue($ControllerKey-1, $Parts, NULL); $Controller = GetValue($ControllerKey, $Parts, NULL); $Controller = ucfirst(strtolower($Controller)); // Check for a file extension on the controller. $Ext = strrchr($Controller, '.'); if ($Ext) { $Controller = substr($Controller, 0, -strlen($Ext)); $Ext = strtoupper(trim($Ext, '.')); if (in_array($Ext, array(DELIVERY_METHOD_JSON, DELIVERY_METHOD_XHTML, DELIVERY_METHOD_XML))) { $this->_DeliveryMethod = strtoupper($Ext); } } 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('Quiet' => TRUE)); if ($ControllerPath !== FALSE) { // This was a guess search with no specified application. Look up // the application folder from the controller path. if (is_null($Application)) { $InterimPath = explode('/controllers/', $ControllerPath); array_pop($InterimPath); // Get rid of the end. Useless; $InterimPath = explode('/', trim(array_pop($InterimPath))); $Application = array_pop($InterimPath); if (!in_array($Application, $this->EnabledApplicationFolders())) return FALSE; } Gdn_Autoloader::Priority( Gdn_Autoloader::CONTEXT_APPLICATION, $Application, Gdn_Autoloader::MAP_CONTROLLER, Gdn_Autoloader::PRIORITY_TYPE_PREFER, Gdn_Autoloader::PRIORITY_PERSIST); $this->_ControllerName = $Controller; $this->_ApplicationFolder = (is_null($Application) ? '' : $Application); $this->_ControllerFolder = ''; $Length = sizeof($Parts); if ($Length > $ControllerKey + 1) list($this->_ControllerMethod, $this->_DeliveryMethod) = $this->_SplitDeliveryMethod($Parts[$ControllerKey + 1]); if ($Length > $ControllerKey + 2) { for ($i = $ControllerKey + 2; $i < $Length; ++$i) { if ($Parts[$i] != '') $this->_ControllerMethodArgs[] = $Parts[$i]; } } require_once($ControllerPath); throw new GdnDispatcherControllerFoundException(); } return FALSE; }
protected function FindController($ControllerKey, $Parts) { $Controller = GetValue($ControllerKey, $Parts, NULL); $Controller = ucfirst(strtolower($Controller)); $Application = GetValue($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('Quiet' => TRUE)); if ($ControllerPath) { // This was a guess search with no specified application. Look up // the application folder from the controller path. if (is_null($Application)) { $InterimPath = explode('/controllers/', $ControllerPath); array_pop($InterimPath); // Get rid of the end. Useless; $InterimPath = explode('/', trim(array_pop($InterimPath))); $Application = array_pop($InterimPath); if (!in_array($Application, $this->EnabledApplicationFolders())) { return FALSE; } } Gdn_Autoloader::Priority(Gdn_Autoloader::CONTEXT_APPLICATION, $Application, Gdn_Autoloader::MAP_CONTROLLER, Gdn_Autoloader::PRIORITY_TYPE_PREFER, Gdn_Autoloader::PRIORITY_PERSIST); $this->ControllerName = $Controller; $this->_ApplicationFolder = is_null($Application) ? '' : $Application; $this->ControllerFolder = ''; $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]; } } } require_once $ControllerPath; throw new GdnDispatcherControllerFoundException(); } return FALSE; }
protected function FindController($ControllerKey, $Parts) { $Controller = GetValue($ControllerKey, $Parts, NULL); $Controller = ucfirst(strtolower($Controller)); $Application = GetValue($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); 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); if (!in_array($Application, $this->EnabledApplicationFolders())) { 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; $this->ControllerFolder = ''; $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; }