Example #1
0
 /**
  * map individual route Uri's
  *
  * @return mixed[object|void]
  */
 function translateUri(Route $object)
 {
     //empty and move on
     if (empty($object)) {
         return $object;
     }
     //check for our special terms __HOME__, __404__ etc
     // the / states the start and end of the pattern
     // ^_{2} states the string must start with 2 underscores
     // ([a-zA-Z0-9])+ one or more alphanumeric
     // _{2}$ the string must end with 2 underscores
     // the / denotes the end of our string
     if (preg_match('/^_{2}([a-zA-Z0-9])+_{2}$/', $object->getUri(), $m)) {
         //if we find one, move on, __KEYWORDS__ are dealt with seperately
         $object->is_special = true;
     }
     $uri = $object->getUri();
     //loop through our route map array and switch values in both uri and pattern strings
     foreach ($this->getRouteMap() as $key => $value) {
         //look for any matches within our uri
         if (stripos($uri, $key) !== false and $object->is_special === false) {
             //make our uri - if value is empty, add a slash to key to be removed
             $uri = str_ireplace($value ? $key : $key . '/', $value, $uri);
         }
         //look for any matches within our pattern
         if (stripos($pattern, $key) !== false) {
             //if we have a key called '{method}' and its empty, we're at the root level, so add 'index'
             $value = (in_array($key, array('{method}', '{submethod}')) and $value == '') ? 'index' : $value;
             //update our pattern variable
             $pattern = str_ireplace($key, $value, $pattern);
         }
     }
     //prepend the request type to the method, if we have a normal route
     if (strpos($pattern, '::') and $object->is_special === false) {
         //explode $pattern into $class and $method
         list($class, $method) = explode('::', $pattern);
         //put back together
         $pattern = $class . '::' . $this->request_type . '_' . $method;
     }
     //update the mapped pattern, keeping the original pattern
     $object->setMappedUri($uri);
     return $object;
 }