Example #1
0
 /**
  *  VALIDATE THE ROUTE
  *  Validates the supplied segments.
  * Attempts to determine the path to the controller.
  **/
 private static function _validate($segments = false)
 {
     //  if no segments are specified we use the current class and method.
     if (!$segments) {
         $segments = array(self::$_CLS, self::$_MTD);
     }
     if (!is_array($segments)) {
         Core::error('ARRTYP', 'LIBTIT', array(__METHOD__, 'segments'));
     }
     // does the requested controller file exist?
     if (file_exists(CTRL . $segments[0] . EXT)) {
         return $segments;
     }
     // in a subfolder ?
     if (is_dir(CTRL . $segments[0])) {
         // Set the current dir and remove it from the array
         self::$_DIR = $segments[0];
         $segments = array_slice($segments, 1);
         // does the requested controller file exists in subfolder?
         if (count($segments) > 0) {
             if (!file_exists(CTRL . self::$_DIR . '/' . $segments[0] . EXT)) {
                 Core::error404();
             }
         } else {
             if (!file_exists(CTRL . self::$_DIR . '/' . self::$_CTR . EXT)) {
                 Core::error('RTRCTR', 'LIBTIT', __CLASS__);
             }
             // we set the default controller
             self::$_CLS = self::$_CTR;
             self::$_MTD = 'index';
         }
         return $segments;
     }
     // if default controller doesn't exists throw an error instead of the 404.
     if (!file_exists(CTRL . self::$_CTR . EXT)) {
         Core::error('RTRCTR', 'LIBTIT', __CLASS__);
     }
     Core::error404(Uri::string());
 }