Example #1
0
 /**
  * Takes an array of URL parameters and separates the ones that can be used as named arguments
  *
  * @param array $params Associative array of URL parameters.
  * @param string $controller Name of controller being routed.  Used in scoping.
  * @param string $action Name of action being routed.  Used in scoping.
  * @return array
  * @access public
  * @static
  */
 function getNamedElements($params, $controller = null, $action = null)
 {
     $self =& Router::getInstance();
     $named = array();
     foreach ($params as $param => $val) {
         if (isset($self->named['rules'][$param])) {
             $rule = $self->named['rules'][$param];
             if (Router::matchNamed($param, $val, $rule, compact('controller', 'action'))) {
                 $named[$param] = $val;
                 unset($params[$param]);
             }
         }
     }
     return array($named, $params);
 }
Example #2
0
 /**
  * Takes an passed params and converts it to args
  *
  * @param array $params
  * @return array Array containing passed and named parameters
  * @access public
  * @static
  */
 function getArgs($args, $options = array())
 {
     $_this =& Router::getInstance();
     $pass = $named = array();
     $args = explode('/', $args);
     $greedy = $_this->named['greedy'];
     if (isset($options['greedy'])) {
         $greedy = $options['greedy'];
     }
     $context = array();
     if (isset($options['context'])) {
         $context = $options['context'];
     }
     $rules = $_this->named['rules'];
     if (isset($options['named'])) {
         $greedy = isset($options['greedy']) && $options['greedy'] === true;
         foreach ((array) $options['named'] as $key => $val) {
             if (is_numeric($key)) {
                 $rules[$val] = true;
                 continue;
             }
             $rules[$key] = $val;
         }
     }
     foreach ($args as $param) {
         if (empty($param) && $param !== '0' && $param !== 0) {
             continue;
         }
         $param = $_this->stripEscape($param);
         if ((!isset($options['named']) || !empty($options['named'])) && strpos($param, $_this->named['separator']) !== false) {
             list($key, $val) = explode($_this->named['separator'], $param, 2);
             $hasRule = isset($rules[$key]);
             $passIt = !$hasRule && !$greedy || $hasRule && !Router::matchNamed($key, $val, $rules[$key], $context);
             if ($passIt) {
                 $pass[] = $param;
             } else {
                 $named[$key] = $val;
             }
         } else {
             $pass[] = $param;
         }
     }
     return compact('pass', 'named');
 }