예제 #1
0
 /**
  * Find the controller that matches the route requested
  *
  * @param	Route		the given Route object
  * @return	mixed		the match array or false
  */
 protected static function find_controller($match)
 {
     // First port of call: request for a module?
     if (\Fuel::module_exists($match->segments[0])) {
         // make the module known to the autoloader
         \Fuel::add_module($match->segments[0]);
         $segments = $match->segments;
         // first check if the controller is in a directory.
         $match->module = array_shift($segments);
         $match->directory = count($segments) ? array_shift($segments) : null;
         $match->controller = count($segments) ? array_shift($segments) : $match->module;
         // does the module controller exist?
         if (class_exists(ucfirst($match->module) . '\\Controller_' . ucfirst($match->directory) . '_' . ucfirst($match->controller))) {
             $match->action = count($segments) ? array_shift($segments) : null;
             $match->method_params = $segments;
             return $match;
         }
         $segments = $match->segments;
         // then check if it's a module controller
         $match->module = array_shift($segments);
         $match->directory = null;
         $match->controller = count($segments) ? array_shift($segments) : $match->module;
         // does the module controller exist?
         if (class_exists(ucfirst($match->module) . '\\Controller_' . ucfirst($match->controller))) {
             $match->action = count($segments) ? array_shift($segments) : null;
             $match->method_params = $segments;
             return $match;
         }
         $segments = $match->segments;
         // do we have a module controller with the same name as the module?
         if ($match->controller != $match->module) {
             array_shift($segments);
             $match->controller = $match->module;
             if (class_exists(ucfirst($match->module) . '\\Controller_' . ucfirst($match->controller))) {
                 $match->action = count($segments) ? array_shift($segments) : null;
                 $match->method_params = $segments;
                 return $match;
             }
         }
     }
     $segments = $match->segments;
     // It's not a module, first check if the controller is in a directory.
     $match->directory = array_shift($segments);
     $match->controller = count($segments) ? array_shift($segments) : $match->directory;
     if (class_exists('Controller_' . ucfirst($match->directory) . '_' . ucfirst($match->controller))) {
         $match->action = count($segments) ? array_shift($segments) : null;
         $match->method_params = $segments;
         return $match;
     }
     $segments = $match->segments;
     // It's not in a directory, so check for app controllers
     $match->directory = null;
     $match->controller = count($segments) ? array_shift($segments) : $match->directory;
     // We first want to check if the controller is in a directory.
     if (class_exists('Controller_' . ucfirst($match->controller))) {
         $match->action = count($segments) ? array_shift($segments) : null;
         $match->method_params = $segments;
         return $match;
     }
     // none of the above. I give up. We've found ziltch...
     $match->action = null;
     $match->controller = null;
     return $match;
 }
예제 #2
0
 /**
  * Find the controller that matches the route requested
  *
  * @param	Route  $match  the given Route object
  * @return	mixed  the match array or false
  */
 protected static function parse_match($match)
 {
     $namespace = '';
     $segments = $match->segments;
     $module = false;
     // First port of call: request for a module?
     if (\Fuel::module_exists($segments[0])) {
         // make the module known to the autoloader
         \Fuel::add_module($segments[0]);
         $match->module = array_shift($segments);
         $namespace .= ucfirst($match->module) . '\\';
         $module = $match->module;
     }
     if ($info = static::parse_segments($segments, $namespace, $module)) {
         $match->controller = $info['controller'];
         $match->action = $info['action'];
         $match->method_params = $info['method_params'];
         return $match;
     } else {
         return null;
     }
 }
예제 #3
0
 /**
  * Creates the new Request object by getting a new URI object, then parsing
  * the uri with the Route class.
  *
  * Usage:
  *
  *     $request = new Request('foo/bar');
  *
  * @param   string  the uri string
  * @param   bool    whether or not to route the URI
  * @return  void
  */
 public function __construct($uri, $route = true)
 {
     $this->uri = new \Uri($uri);
     // check if a module was requested
     if (count($this->uri->segments) and $modpath = \Fuel::module_exists($this->uri->segments[0])) {
         // check if the module has routes
         if (file_exists($modpath .= 'config/routes.php')) {
             // load and add the module routes
             $modroutes = \Config::load(\Fuel::load($modpath), $this->uri->segments[0] . '_routes');
             foreach ($modroutes as $name => $modroute) {
                 switch ($name) {
                     case '_root_':
                         // map the root to the module default controller/method
                         $name = $this->uri->segments[0];
                         break;
                     case '_404_':
                         // do not touch the 404 route
                         break;
                     default:
                         // prefix the route with the module name if it isn't done yet
                         if (strpos($name, $this->uri->segments[0] . '/') !== 0 and $name != $this->uri->segments[0]) {
                             $name = $this->uri->segments[0] . '/' . $name;
                         }
                         break;
                 }
                 \Config::set('routes.' . $name, $modroute);
             }
             // update the loaded list of routes
             \Router::add(\Config::get('routes'));
         }
     }
     $this->route = \Router::process($this, $route);
     if (!$this->route) {
         return;
     }
     if ($this->route->module !== null) {
         $this->module = $this->route->module;
         \Fuel::add_module($this->module);
         $this->add_path(\Fuel::module_exists($this->module));
     }
     $this->directory = $this->route->directory;
     $this->controller = $this->route->controller;
     $this->action = $this->route->action;
     $this->method_params = $this->route->method_params;
     $this->named_params = $this->route->named_params;
 }
예제 #4
0
 /**
  * Creates the new Request object by getting a new URI object, then parsing
  * the uri with the Route class.
  *
  * Usage:
  *
  *     $request = new Request('foo/bar');
  *
  * @param   string  the uri string
  * @param   bool    whether or not to route the URI
  * @return  void
  */
 public function __construct($uri, $route = true)
 {
     $this->uri = new \Uri($uri);
     logger(\Fuel::L_INFO, 'Creating a new Request with URI = "' . $this->uri->uri . '"', __METHOD__);
     // check if a module was requested
     if (count($this->uri->segments) and $module_path = \Fuel::module_exists($this->uri->segments[0])) {
         // check if the module has routes
         if (is_file($module_path .= 'config/routes.php')) {
             $module = $this->uri->segments[0];
             // load and add the module routes
             $module_routes = \Fuel::load($module_path);
             $prepped_routes = array();
             foreach ($module_routes as $name => $_route) {
                 if ($name === '_root_') {
                     $name = $module;
                 } elseif (strpos($name, $module . '/') !== 0 and $name != $module and $name !== '_404_') {
                     $name = $module . '/' . $name;
                 }
                 $prepped_routes[$name] = $_route;
             }
             // update the loaded list of routes
             \Router::add($prepped_routes, null, true);
         }
     }
     $this->route = \Router::process($this, $route);
     if (!$this->route) {
         return;
     }
     $this->module = $this->route->module;
     $this->controller = $this->route->controller;
     $this->action = $this->route->action;
     $this->method_params = $this->route->method_params;
     $this->named_params = $this->route->named_params;
     if ($this->route->module !== null) {
         $this->add_path(\Fuel::module_exists($this->module));
     }
 }
예제 #5
0
파일: request.php 프로젝트: novius/core
	/**
	 * Creates the new Request object by getting a new URI object, then parsing
	 * the uri with the Route class.
	 *
	 * Usage:
	 *
	 *     $request = new Request('foo/bar');
	 *
	 * @param   string  the uri string
	 * @param   bool    whether or not to route the URI
	 * @return  void
	 */
	public function __construct($uri, $route = true)
	{
		$this->uri = new \Uri($uri);

		// check if a module was requested
		if (count($this->uri->segments) and $modpath = \Fuel::module_exists($this->uri->segments[0]))
		{
			// check if the module has custom routes
			if (file_exists($modpath .= 'config/routes.php'))
			{
				// load and add the routes
				\Config::load(\Fuel::load($modpath), 'routes');
				\Router::add(\Config::get('routes'));
			}
		}

		$this->route = \Router::process($this, $route);

		if ( ! $this->route)
		{
			return false;
		}

		if ($this->route->module !== null)
		{
			$this->module = $this->route->module;
			\Fuel::add_module($this->module);
			$this->add_path(\Fuel::module_exists($this->module));
		}

		$this->directory = $this->route->directory;
		$this->controller = $this->route->controller;
		$this->action = $this->route->action;
		$this->method_params = $this->route->method_params;
		$this->named_params = $this->route->named_params;
	}